Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Select nodes where an attribute contains some sub-text

Reply
Thread Tools

Select nodes where an attribute contains some sub-text

 
 
Duncan
Guest
Posts: n/a
 
      02-09-2006
Can I use the contains() function within an xpath query to return a
node whose attribute contains some text?

Something like: selectNodes("//Dataset[@Pattern contains(@Pattern,
'xyz')]

so for the given xml doc

<root>
<Datasets>
<Dataset name="dataset1" Pattern="abc" AnotherAttribute="xyz"/>
<Dataset name="dataset2" Pattern="xyz" AnotherAttribute="xyz"/>
<Dataset name="dataset3" Pattern="vwxyz"/>
</Datasets>
</root>

The nodes dataset2 and dataset3 would be returned because their
'Pattern' attribute contains the text 'xyz'.

Many thanks,

Duncan.

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-09-2006


Duncan wrote:

> Can I use the contains() function within an xpath query to return a
> node whose attribute contains some text?


Yes.


> Something like: selectNodes("//Dataset[@Pattern contains(@Pattern,
> 'xyz')]


That is syntactically wrong. A possible XPath expression could be
/root/Datasets/Dataset[contains(@Pattern, 'xyz')]


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Duncan
Guest
Posts: n/a
 
      02-09-2006
By jove, it works!

Thanks,

Duncan.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
How to select nodes whose parent has a specific attribute bearclaws XML 4 03-01-2005 10:05 PM
mz js select nodes with xpath, having by specific attribute named'class' the 'subvalue part' set Marek Mänd Javascript 1 02-20-2005 04:43 PM
Regex problem, match if line contains <a>, unless it also contains <b> James Dyer Perl 5 02-20-2004 12:29 PM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments