C#:XPath选择包含子字符串属性的节点?

我可以使用XPath选择其代码包含UK的国家/地区节点吗?

      

谢谢。

尝试contains() XPath函数。

就像是:

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

快速谷歌搜索会提供有关XPathfunction的详细信息: http : //www.w3schools.com/xpath/xpath_functions.asp

你需要这样写:

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

您可以将Linq用于XML – 这只是一个想法

像这样的东西:

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

是的,做点什么

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

选择了第一个Country元素