title: Url open with username and password
body: <p>I have started to learn scala , the only other language I know is python.
  I am trying to write a code in scala which I have written in python.
  In that code I have to open a url thats in xml format which require a username and 
  password and then parse it and get the elements which matches string name=ID</p>
  
  <p>Here is my python code</p>
  
  <pre><code>import urllib2
  
  theurl = 'Some url'
  username = 'some username'
  password = 'some password'
  # a great password
  
  passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
  # this creates a password manager
  passman.add_password(None, theurl, username, password)
  # because we have put None at the start it will always
  # use this username/password combination for  urls
  # for which `theurl` is a super-url
  
  authhandler = urllib2.HTTPBasicAuthHandler(passman)
  # create the AuthHandler
  
  opener = urllib2.build_opener(authhandler)
  
  urllib2.install_opener(opener)
  # All calls to urllib2.urlopen will now use our handler
  # Make sure not to include the protocol in with the URL, or
  # HTTPPasswordMgrWithDefaultRealm will be very confused.
  # You must (of course) use it when fetching the page though.
  
  pagehandle = urllib2.urlopen(theurl)
  # authentication is now handled automatically for us
  
  
  ##########################################################################
  
  from xml.dom.minidom import parseString
  
  file = pagehandle
  
  #convert to string:
  data = file.read()
  #close file because we dont need it anymore:
  file.close()
  #parse the xml you downloaded
  dom = parseString(data)
  #retrieve the first xml tag (&lt;tag&gt;data&lt;/tag&gt;) that the parser finds with name tagName:
  xmlData=[]
  for s in dom.getElementsByTagName('string'):
      if s.getAttribute('name') == 'ID':
          xmlData.append(s.childNodes[0].data)
  print xmlData
  </code></pre>
  
  <p>and this is what I have written in scala to open a url I am still to figure out how to 
  handle it with username password I have searched on internet regarding the same and still 
  didnt get what I am looking for.</p>
  
  <pre><code>object URLopen {
    import java.net.URL
    import scala.io.Source.fromURL
    def main(arg: Array[String]){
      val u = new java.net.URL("some url")
      val in = scala.io.Source.fromURL(u) 
      for (line &lt;- in.getLines)
        println(line)
      in.close()
    }
  }
  </code></pre>
  
  <p>Can someone help me to handle the url open with username password
  or tell me from where I can learn how to do it?
  In python we have docs.python.org/library/urllib2.html
  where I can learn about various modules and how to use them.
  Is there some link for scala too?</p>
  
  <p>PS: Any help regarding parsing xml and getting the elements with string name= ID is also welcomed</p>