Link to home
Start Free TrialLog in
Avatar of kvigor
kvigor

asked on

I want to capture an XML attribute value in a string variable

<!-- This is what the XML File looks like
This challenge is I don't know the attribute's value (because it's dynamically created) however I will always know the username value.-->

<!--ALSO LET ME KNOW IF I SHOULD JUST USE TEXT MEMBER INSTEAD OF XML MEMBERS-->

<users>
  <users
    <role>
        admin
    </role>
    <username ID="2CF8C226-E8BE-4428-8C00-C6A047CC9024">
       john
    </username>
    <password ID="2CF8C226-E8BE-4428-8C00-C6A047CC9024">>
      password
    </password>
  </user>
</users>

<!-- Psuedo code:
go get the value of the ID attribute where the username is equal to john-->
// An attempt to achieve this:
 
xmlDocPath = Server.MapPath("XMLAuth/userAuthentication.xml")
        doc = New XPathDocument(xmlDocPath)
        nav = doc.CreateNavigator()
// Try to find the username john so we can store it in a variable
// Then get the the value of the id attribute
// Store that value in a variable
// Then go get the password where ID attribute is equal to the attribute we found in username element
xPathIter = nav.[Select]("users/user/username")
 
        If xPathIter.Count > 0 Then
            While xPathIter.MoveNext()
                Response.Write(xPathIter.Current.InnerXml.ToString())
            End While
        End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of shahjapan
shahjapan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kvigor
kvigor

ASKER

Thanks it works to target the.  I would've liked to see how to traverse the doc from this code though.