sharkyenergy sharkyenergy - 7 months ago 6
Vb.net Question

Invalid Token in xmldoc.selectnodes if string contains a dot

I'm searching for a string in a XML file. The string has a dot in it, and causes a invalid token error to appear.

For Each d As XmlNode In xmlDoc2.SelectNodes("//*[@ StructType = '" & r.Item(2).ToString & "'")

r.Item(2).ToString = CX8090_QA.Publishing.Errors


I would like to search for this string just as it is, and have the ' in place too. But it doesn't seem to take it as a string.

thanks

Answer

As posted, your XPath expression is missing closing square bracket :

xmlDoc2.SelectNodes("//*[@StructType = '" & r.Item(2).ToString & "']")

Other than that it should be fine as long as the dynamic string part of the XPath doesn't contain single-quote, which will conflict string-literal delimiter being used.