<?xml version="1.0" encoding="utf-8"?>
<users>
  <user>
    <name>aditi</name>
    <password>A802CEDA2B04377E3265FC30C3D7CE9F4FADBEA0</password>
    <firstname>aditi</firstname>
    <lastname>surname</lastname>
    <usertype>1</usertype>
  </user>
 <user>
    <name>jillian</name>
    <password>A802CEDA2B04377E3265FC30C3D7CE9F4FADBEA0</password>
    <firstname>jillian</firstname>
    <lastname>chen</lastname>
    <usertype>2</usertype>
  </user>
 </users>

How can I search for the <name> and the <password> node so that I can authenticate the login using this XML in ASP.NET?

Currently I am looking at something like this -

Dim strXMLDoc As String = Left(System.Web.HttpContext.Current.Session("strCurrPath"), InStrRev(System.Web.HttpContext.Current.Session("strCurrPath"), "\")) & "WEContent" & "\users.xml"
Dim objXMLDoc As New XmlDocument()
lblErrorMessage.Text = ""
        Try
            'Load the XML document
            objXMLDoc.Load(strXMLDoc)
        Catch ex As Exception
            lblErrorMessage.Text = ex.Message & "<br />" & ex.Source
        End Try
        
Dim xmlNodeUser As XmlNode = objXMLDoc.SelectSingleNode("/user")
dim xmlNodePass As XmlNode = objXMLDoc.SelectSingleNode("/password")

But I am completely confused as to how I am going to authenticate the usernames and passwords from an XML file.

Help is urgently needed. :S

Thanks,
Aditi

Now I am looking at something different -

<?xml version="1.0" encoding="utf-8"?>
<users>
  <user>
    <name>aditi</name>
    <password>A802CEDA2B04377E3265FC30C3D7CE9F4FADBEA0</password>
    <firstname>aditi</firstname>
    <lastname>surname</lastname>
    <usertype>1</usertype>
  </user>
 <user>
    <name>jillian</name>
    <password>A802CEDA2B04377E3265FC30C3D7CE9F4FADBEA0</password>
    <firstname>jillian</firstname>
    <lastname>chen</lastname>
    <usertype>2</usertype>
  </user>
 </users>

How can I search for the <name> and the <password> node so that I can authenticate the login using this XML in ASP.NET?

Currently I am looking at something like this -

Help with Code Tags (Toggle Plain Text)

Public Sub LoginCheck(ByVal pUrName As String, ByVal pUrPassword As String)
        Dim s As New System.Text.StringBuilder()
        Dim objXMLDoc As New XmlDocument()
        Dim strXMLDoc As String = Left(System.Web.HttpContext.Current.Session("strCurrPath"), InStrRev(System.Web.HttpContext.Current.Session("strCurrPath"), "\")) & "WEContent" & "\users.xml"
        Try
            'Load the XML document
            objXMLDoc.Load(strXMLDoc)
        Catch ex As Exception
            lblErrorMessage.Text = ex.Message & "<br />" & ex.Source
        End Try
        Dim navigator As XPathNavigator = objXMLDoc.CreateNavigator
        Dim count As Integer
        count = navigator.Select("/users/user/name").Count

        'Navigate to the right nodes
        navigator.MoveToChild("users", "")
        navigator.MoveToChild("user", "")

        'Loop through all the user nodes
        Dim I As Integer

        For I = 0 To I < count
            navigator.MoveToChild("name", "")
            If navigator.InnerXml = pUrName Then
                lblErrorMessage.Text = "Username is valid"
            ElseIf navigator.InnerXml <> pUrName Then
                lblErrorMessage.Text = "Username is invalid"
            End If
            ''Move to the parent book element
            navigator.MoveToParent()
            ''Move to the next sibling book element
            navigator.MoveToNext()

        Next
        I = I + 1
        'navigator.MoveToRoot()
        Response.Write(navigator.OuterXml)

    End Sub

But I am completely confused as to how I am going to authenticate the usernames and passwords from an XML file.

Help is urgently needed.

Thanks,
Aditi

This article has been dead for over six months. Start a new discussion instead.