开发者

What is the proper XPath query to find the value in this XML document?

Suppose I have this XML document...

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

I want to get the value of the "str" element based on a known value of the elements "name" attribute so I use the following XPath query...

str[@name='My node's attribute']

But that doesn't work for me at least not in classic ASP and C# because of the si开发者_StackOverflow中文版ngle 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 the restriction that I can't change the XML document.


Use " in the xpath instead:-

C#

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

VBScript

 Dim xpath : xpath = "str[@name=""My node's attribute""]"


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


Try:

str[@name='My node''s attribute']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜