What is the correct XPath query to look up a value in this XML document?

Suppose I have this XML document ...

<root>
  <str name="My node attribute">My string value</str>
</root>

I want to get the value of the str element based on the known value of the element's name attribute, so I use the following XPath query ...

str[@name='My node attribute']

But this does not work for me, at least not in classic ASP and C # because of a single quote, which, of course, conflicts with the single quotes used in XPath syntax. An exception is thrown in both cases.

What is a possible solution here if I have a limitation that I cannot modify the XML document.

+2
source share
3 answers

Use "in xpath instead: -

WITH#

 string xpath = "str[@name=\"My node attribute\"]";

Vbscript

 Dim xpath : xpath = "str[@name=""My node attribute""]"
+2
source

Try:

str[@name='My node' attribute']
0
str[@name='My node&apos;s attribute']
0
source

Source: https://habr.com/ru/post/1730250/


All Articles