[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Xoath quote escaping

Subject: Xoath quote escaping
From: "Duane Hitz" <dhitz@xxxxxxxxxxxxxxxx>
Date: Sat, 28 Apr 2007 08:27:21 -0600
 Xoath quote escaping
All,

I have a situation where I am building an XPath expression in JavaScript to select nodes from an XML document. The content of the nodes could contain double quotes, single quotes or both at the same time. It is user-entered data, so I have no control ultimately over what the content contains.

The content might be (brackets excluded): [This is some "quoted" content of Ted's]

The dynamically built xpath expression might look like (where subNodeValue is the above content):

1) "//node[" + subNodeName + " = '" + subNodeValue + "']"

... except for the single quote problem... or:

2) "//node[" + subNodeName + " = \"" + subNodeValue + "\"]"

... except for the double quote problem... or even:

3) "//node[" + subNodeName + " = &quot;" + subNodeValue + "&quot;]"

...except that this just doesn't work.

Any thoughts on how to make this work? Is it possible?

I've read everything I can find on quote escaping (on this list and elsewhere) and there doesn't appear to be a solution that covers this case (I know XPath 2 is supposed to allow "" escaping - unfortunately, we're stuck on IE6+ & MSXML3).

We are dynamically displaying rows in a table that meet the xpath criteria... setting a @showing attribute and then re-transforming... so it really has to be in JavaScript.

One option would be to replace (s/"/'/g or s/"/''/g) all double quotes on the server side when building the XML - and then use option 2 above. I don't really want to change user-entered data. It is, sadly, what I've come down to. I'm hoping there's a more elegant solution to this.

Thanks for any help...

Duane

Current Thread

Back To School Sale!

Save 30% off all Stylus Studio 2008 Products when you purchase from our Online Shop.

Offer ends August 31, 2008.

Coupon Code
TRTY-C4JV-OFF

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.