Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding nodes that contain a given string

Status
Not open for further replies.

gacaccia

Technical User
May 15, 2002
258
US
i'm working with IE and the "selectNodes" and "selectSingleNode" methods to retrieve node results from an xml file. i know how to use some basic xPath commands to query the xml document to get what i want. however, one thing i can't figure out is how to select a node based on whether its text is equal to or contains a given string.

for example, i have an xml document with a node called "description". i want to have a search utility where the user can type in some text and click search and it will return all nodes that contain a "description" node that contains the search string. i tried using the xPath function "contains", but couldn't get that to work. any thoughts?

as an example, my xml document might look like...
Code:
<item id=&quot;1&quot;>
  <description>description of item one</descriptioin>
</item>
<item id=&quot;2&quot;>
  <description>description of item two</description>
</item>
my javascript code might look like...
Code:
var nodeSet = xmlItems.XMLDocument.selectNodes(criteria)
i found one example that showed a general syntax of...
Code:
...selectNodes(&quot;//description [contains(text(),searchString)]&quot;);
...but it doesn't recognize &quot;contains&quot; to be a valid method.

thanks,

glenn
 
Hi Glenn,

Are you sure your code doesn't recognize the XPath function contains?

What is XMLDocument for kind of object? I guess it's an XMLDomDocument object. What I'm interested in is what version of IE you are using and what verson of XMLDomDocument you're instanciating.

If you use the wrong version of IE or of the XMLDomDocument object your code will not recognize certain XPath functions.

Could you post some more javascript code??

Jordi

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top