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

半腔热情 提交于 2019-12-05 23:00:01

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

RRaveen

You need write it this way:

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!