Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

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.

  • 2
1 Solution
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?

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now