Nov 24

Written by: Soul Solutions
Friday, 24 November 2006 

BronwenWeeGo.jpgToday i had to filter an xml document based on the start value of an attribute and it took me ages to work it out as before i'd always done exact matches.  Plus couldn't find any egs where they used anything bar =.  So if i have a xml schema like


<books>
	<book name="Bronwens adventure"></book>
	<book name="Bronwen vacations"></book>
</books>

and i have a XMLDocument with this in it.  If i want to find all the book's whose name starts with "Bronwen" I can do a xpath query as follows:


doc.SelectNodes("//book[starts-with(@name,'Bronwen');

Tags:

2 comment(s) so far...

Re: XPath - how to find all elements where an attribute starts-with a text value

Thanks handy!

By Scott on   Saturday, 25 July 2009

Nice tip

Thanks, this is a great tip. Exactly what I was looking for.

By craig on   Monday, 6 June 2011

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
Copyright © 2002-2009 Soul Solutions Pty Ltd. | Login