Been a while since I used VB. I am having a problem running an XPATH query on some XML.
I have the following XML:
<configuration>
<my.app.application>
<dummydatasets>
<dummydataset tag="\\server\XX_YY_ZZ" />
<dummydataset tag="default" mode="random" />
</dummydatasets>
</my.app.application>
</configuration>
I am trying to find the dummy data set using XPATH. The XPATH to evaluate is:
//configuration/my.app.application/dummydatasets/dummydataset [@tag=”\\server\XX_YY_ZZ”]
So that is double backslash, “server”, slash, “XX_YY_ZZ”.
The VB6 code is as follows:
Dim xmlDoc As New DOMDocument
If xmlDoc.Load(path to xml) Then
Dim theTag As String
theTag = "\\server\XX_YY_ZZ"
Dim xPathQuery As String
xPathQuery = "//configuration/my.app.application/dummydatasets/dummydataset [@tag='" & theTag & "']"
Set xmlNode = xmlDoc.selectSingleNode(xPathQuery)
End If
The tag cannot be found. xmlNode is set to Nothing. However using a utility such as XML Copy Editor, I can enter the XPATH and the node is found. However, if I select the default tag, the code works fine.
I didn’t think there would be a problem with the tag attribute’s text with the backslash and underscores. I am hopefully wrong.
Any thoughts,
Thanks
Andez
I tested this and the issue is with the backslashes. Underscores were fine but the backslashes caused issues.
You need to specify the SelectionLanguage in DOMDocument after it is created:
Here is the source page.