我可以使用XPath来选择其代码包含英国的国家节点吗?C#:XPath选择节点的属性包含一个子串?
<country-list>
<Country code="TW,UK,MY" />
<Country code="US,CA,MX" />
<Country code="IN,PR,VI,IR" />
<Country code="Others" />
</country-list>
谢谢。
我可以使用XPath来选择其代码包含英国的国家节点吗?C#:XPath选择节点的属性包含一个子串?
<country-list>
<Country code="TW,UK,MY" />
<Country code="US,CA,MX" />
<Country code="IN,PR,VI,IR" />
<Country code="Others" />
</country-list>
谢谢。
尝试 XPath函数。
喜欢的东西:
/Country[fn:contains(@code, "UK")]
快速谷歌搜索变成了细节上的XPath功能: http://www.w3schools.com/xpath/xpath_functions.asp
你可以使用LINQ到XML - 就像一个想法
事情是这样的:
var countryElement = from country in countryElement.GetAttribute("code")
where country.Value.Contains("UK")
select countryElement;
是,这样做
//Country[contains(@code, 'UK')]
其选择的第一个国元
Y你需要这样写:
/country-list/Country[contains(@code,'UK')]
只是好奇你为什么接受答案时,答案并没有真正解决你的问题? – 2009-11-24 03:21:17