Quotes in XPath pattern

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.

Who is Participating?

Improve company productivity with a Business Account.Sign Up

BigRatConnect With a Mentor Commented:
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!
KostaAuthor Commented:
Thanks for the help. I hoped there is something built-in.
KostaAuthor Commented:
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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.