Quotes in XPath pattern

Posted on 2002-04-24
Last Modified: 2006-11-17
I use the XML data island on HTML page to hold data on categories and products assigned to them. In some places I have to add and remove products to categories. So, to find a product in a category node, I use this syntax:

set prd = nod.selectsinglenode("Products/Product[@name=""" & tag.innerText & """]")

wherre tag.innerText contain the product name. The problem is when a product name qontains double quotes ("). I could use this syntax:

set prd = nod.selectsinglenode("Products/Product[@name='" & tag.innerText & "']")

but in this case, an error rised when a product name contain single quotes. Is there some technique to solve this? Like for example in SQL, if a criteria contain a quote, I just replace the quote bu two quotes.

Question by:Kosta
  • 2
LVL 27

Accepted Solution

BigRat earned 50 total points
ID: 6968193
A very interesting question which has just made me think about the way I do it - perhaps this would be better!

If you have an XML document where any of these quote characters occur in attributes, you must convert them to entities.

I suspect, although I have not tried it, that that is the way to do it here. So something like :-

      set searchString = escapeToEntities(tag.innerText);
      set prd = nod.selectSingleNode("Products/Product[@name='" & searchString & "']");

where escapeToEntities does a regular expression substitution from ' to &quote; etc...

try that out!

Author Comment

ID: 6977149
Thanks for the help. I hoped there is something built-in.

Author Comment

ID: 7041155
No, the solution of replacing " by &quote; does not work. It turned out, that the XML DOM does the replacing itself. When I am looking at the XML data, I see that all double quotes are actually replaced by &quote;. But this does not help, because if I use this pattern:

pattern="//Category[@name=""" & replace(tag.innertext,"""",""") & """]/Products"

it does not find the node. It does find the node with this:

pattern="//Category[@name='" & tag.innertext & "']/Products"

but, as I mentioned, in this case a problem rised when the node contain single quotes.
I wonder nobody encountered this problem before me?

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now