Solved

Quotes in XPath pattern

Posted on 2002-04-24
3
542 Views
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.

0
Comment
Question by:Kosta
[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
3 Comments
 
LVL 27

Accepted Solution

by:
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!
0
 
LVL 6

Author Comment

by:Kosta
ID: 6977149
Thanks for the help. I hoped there is something built-in.
0
 
LVL 6

Author Comment

by:Kosta
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?
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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