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-8C0 0-C6A047CC 9024">
john
</username>
<password ID="2CF8C226-E8BE-4428-8C0 0-C6A047CC 9024">>
password
</password>
</user>
</users>
<!-- Psuedo code:
go get the value of the ID attribute where the username is equal to john-->
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-8C0
john
</username>
<password ID="2CF8C226-E8BE-4428-8C0
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER