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
精彩评论