tags:

views:

1710

answers:

3

I want to do this: //*fu, which returns all nodes whose name ends in fu, such as <tarfu /> and <snafu />, but not <fubar />

A: 

I'm not sure about XPath, but I know it can be done with LINQ to XML.

Dim refs = From elem In document...<Reference> _
           Where [email protected]("N")

This is the XML Literal syntax from VB.NET, but it could easily be ported to C#. I'm matching on attributes in this case instead of elements, but you could do that as well.

If you're not able to use LINQ to XML, then I guess I'm not being particularly helpful :)

David Mohundro
+8  A: 

Do something like:

//*[ends-with(name(), 'fu')]

For a good XPath reference, check out the W3Schools tutorial.

Chris Marasti-Georg
+6  A: 

This answer is for XPath 1.0 where there is no equivalent of the XPath 2.0 standard ends-with() function.

The following XPath 1.0 expression selects all elements in the xml document, whose names end with the string "fu":

     //*[substring(name(),string-length(name())-1) = 'fu']

Hope this helped.

Cheers,

Dimitre Novatchev.

Dimitre Novatchev