开发者

C#: XPath to select node with attribute containing a substring?

Could I use XPath to select country node whose code containing UK?

<country-list>
  <Country code="TW,UK,MY" />
  <Country code="US,CA,MX" />
  <Country code="IN,PR,VI,IR" />
  <Country cod开发者_JAVA百科e="Others" /> 
</country-list>

Thanks.


Try the contains() XPath function.

Something like:

/Country[fn:contains(@code, "UK")]

A quick Google search turns up details on XPath functions: http://www.w3schools.com/xpath/xpath_functions.asp


You need write it this way:

/country-list/Country[contains(@code,'UK')]


You could use Linq to XML - just as an idea

Something like this:

var countryElement = from country in countryElement.GetAttribute("code")
  where country.Value.Contains("UK")
  select countryElement;


Yes, do something like

//Country[contains(@code, 'UK')]

which selected the first Country element

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜