Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using XPath functions within XMLDOM...???

Posted on 2006-10-30
5
Medium Priority
?
403 Views
Last Modified: 2007-12-19
I'm currently using XML datasets to display product information to my pages.  I'm using SelectNodes to grab all nodes that I want, and then I loop through the selected nodes to display each product to the page.  So, when I'm browsing by categories, for instance, I have something like this:

Set ProductsList = xmlDoc.SelectNodes("/Inventory/Product[Category='Windows Servers']")

This gives me a node set of all Windows Server products in our inventory and I loop through the set to display each to the page.  Works great.

What I'm trying to do now is make this searchable.  So instead of selecting by category I'll select by taking submitted keywords, matching them up with the descrpitions of the products in the XML document, and then creating the node set based on matching products.  So at first I simply change the line to:

Set ProductsList = xmlDoc.SelectNodes("/Inventory/Product[Description='" & SearchQuery & "']")

Of course, this only works if SearchQuery is exactly the same as one of the Product/Description elements.  In SQL this would basically be saying

SELECT * FROM Products WHERE Description = 'whatever_was_searched'

The SQL way of switching this into a dynamic search would be as simple as this:

SELECT * FROM Products WHERE Description LIKE '%whatever_was_searched%'

I looked up XPath operators and all I find are:

=        (equal to)
!=       (not equal to)
<       (less than)
>       (greater than)
<=      (less than or equal to)
>=      (greater than or equal to)

So none of those will work.  I dig a little further and I find there's a function used in XPath called contains and that is what I should use.  However, I'm having trouble with the syntax of this.  I found a guide at microsoft.com that says to use it like this:

Set nlist = doc.selectNodes("//book/Title[contains(.,'ADO')]")

that particular example would return all books where the word ADO exists in the Title.  So I try and implement this to my own use:

Set ProductsList = xmlDoc.SelectNodes("/Inventory/Product/Description[contains(., 'Windows']")

But I'm getting an unknown method error.

Any information on how to make this work would be greatly appreciated.  Thanks!

0
Comment
Question by:Andrew Angell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17837075
Hi angelleye,
> Set ProductsList = xmlDoc.SelectNodes("/Inventory/Product/Description[contains(.,
> 'Windows']")

if you are looking for Product elements
it would be something like this

Set ProductsList = xmlDoc.SelectNodes("/Inventory/Product[contains(Description, 'Windows')]")


Cheers!
0
 
LVL 11

Author Comment

by:Andrew Angell
ID: 17837126
I got that same error:

msxml3.dll error '80004005'
Unknown method. /Inventory/Product[-->contains(Description<--, 'Windows')]

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 17837368
well, some of the XPath functions are not supported in selectNodes
The support also depends on the msxml version you are using
I suppose you do this using msxml3 and the generic object
Use a least a v2 style
Try installing msxml4 and point effectively to the msxml4 dom object
like this
var oXML = new ActiveXObject("Msxml2.DOMDocument.4.0");
(well that is javascript, it is similar for VB-script)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question