title: Parsing XML and checking values against an elements value
body: <p>I am trying to validate a user's username and password by parsing my XML file filled with users. Currently, my method is coming back as false. It is supposed to go through the child elements of <code>&lt;users&gt;</code> and find the user with the username given, and check the password against the parameters of <code>checkUser()</code>.</p>
  
  <p>I cannot seem to get access to the text inside of the <code>&lt;password&gt;</code> element.</p>
  
  <p>Here is what I have tried thus far:</p>
  
  <pre><code>fun checkUser(username: String, password: String) : Boolean {
      val xmlFile = File("Users.xml")
      val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile)
      var list = doc.getElementsByTagName("user")
      for (i in 0 until list.length) {
          var current = list.item(i)
          if (current.attributes.getNamedItem("id").nodeValue == username) {
              return current.lastChild.textContent == password //trying to check text against given password
          }
      }
      return false
  }
  
  fun main(args: Array&lt;String&gt;) {
      println(checkUser("alec", "123")) //returns false right now
  }
  </code></pre>
  
  <p>Here is my XML File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;users&gt;
      &lt;user id="alec"&gt;
          &lt;username&gt;alec&lt;/username&gt;
          &lt;password&gt;123&lt;/password&gt;
      &lt;/user&gt;
      &lt;user id="john"&gt;
          &lt;username&gt;john&lt;/username&gt;
          &lt;password&gt;415&lt;/password&gt;
      &lt;/user&gt;
  &lt;/users&gt;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p><code>current.attributes.item(0)</code> returns a node, but I need to get the attribute <code>id</code> inside the <code>&lt;user&gt;</code> tag and check it against the given username.</p>
  
  <p><strong>EDIT</strong>
  Fixed code to get id and compare to <code>username</code> parameter, still returns false</p>