A stranger question about Selectsinglenode method
-
Hello,everyone! Now I use the method "selectsinglenode" with xpath to search in my XML, I find a stranger question.In my project, when I used this method at first, it didn't get the node that I wanted, so I created a new project to try the xpath, it could got the node now.(The same xpath and same XML file) Then I deleted some controls in my project which was about the method(not the new one), create new, then the method could find the node! I can't understand it, same xpath, same function,same value,why it happens?:confused::confused: Hope some one could tell me the reason and give me some suggestion!Thank you! The function that I used to search a node was like below:
Dim val As String = ""
Dim xmldoc As New XmlDocument()
Dim xpath As String
Try
xmldoc.Load(Application.StartupPath + "\Flange\Nozzle-Flange-Height.xml")
Dim xmlnode As XmlNode
If Not (Standard = "") Then
xpath = "/Nozzle-Flange-Height/Standard[@value='" + Standard + "']/Flange-type[@type='" + Type + "']/PN[@PN='" + PN + "']/Height[@DN='" + DN + "']"
xmlnode = xmldoc.SelectSingleNode(xpath)
If Not xmlnode Is Nothing Then
val = xmlnode.InnerText
Else
MsgBox("Could not find!")
End If
Else
val = ""
MsgBox("Input by yourself!")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return val