我是使用 XPath 的新手,希望得到任何帮助。我想使用在作为登录页面一部分的文本框中输入的变量来搜索类似于下面的 XML 文件。该变量将用于验证正确的用户。我很难想出正确的表达方式来做到这一点。下面是我一直在使用的示例 Xml 文件的示例。我正在使用 Visual Basic 进行编程。
<Log>
<customer>
<customerid>12345</customerid>
<password>Pass1</password>
<login>00001</login>
<image>Ducati1.jpg</image>
<fname>Julie</fname>
<lname>James</lname>
</customer>
<customer>
<customerid>23456</customerid>
<password>Pass2</password>
<login>00002</login>
<image>Ducati2.jpg</image>
<fname>Bob</fname>
<lname>Barnett</lname>
</customer>
<customer>
<customerid>345678</customerid>
<password>Pass3</password>
<login>00003</login>
<image>Ducati3.jpg</image>
<fname>Callum</fname>
<lname>Claw</lname>
</customer>
</Log>
我尝试过的代码如下: Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
Dim pass As String
Dim user As String
pass = lblPassword.Text
user = lbluser.Text
Dim doc As New XmlDocument
Dim nodes As XmlNodeList
doc.Load(Server.MapPath("App_Data\Customer.xml"))
nodes = doc.SelectNodes("//customer[password = "pass")
For Each node In nodes
TextBox3.Text = node.SelectSingleNode("customerid").InnerText
Next
End Sub
结束类