XPath for attributes with single and double quotes

G

girish

In my XML document, some node attributes data contains both single quot
and double quote characters, such as

<input msg="Hello "World", What's up"/>.

The double quotes are in form of escape sequence in the XML document.
am not able to locate such elements using an XPath expression. I trie
the following:

//*[@msg="Hello "World", What's up"]
Failes with string error at double quote before World

//*[@msg='Hello "World", What's up']
Failes with string error at single quote after What

//*[@msg="Hello "World", What's up"]
I used the escpase sequence for double quote in my xpath which you ar
seeing as acutal double quote in this post.
No Error but does not return any node.

//*[@msg="Hello "World", What's up"]
I used the escpase sequence for both double quotes and single quotes i
my xpath which you are seeing as acutal double quote and single quotesi
this post
No Error but does not return any node

I tried both MSXML 3.0 and MSXML 4.
Any Ideas?
-
giris
 
R

Richard Tobin

girish said:
In my XML document, some node attributes data contains both single quote
and double quote characters [...]
I am not able to locate such elements using an XPath expression.

Yes, annoying isn't it. You can't write an XPath string literal
that contains both kinds of quote.

You can construct the string by breaking it into pieces that use only
one kind of quote, and concatenating them using concat:

//*[@msg=concat('Hello "World", What', "'s up")]

If you're using this expression in a XML attribute (e.g. in an XSLT
stylesheet) you'll still need to escape whichever kind of quote is
used for the attribute value.

-- Richard
 
P

Peter Flynn

girish said:
In my XML document, some node attributes data contains both single quote
and double quote characters, such as

<input msg="Hello "World", What's up"/>.

The double quotes are in form of escape sequence in the XML document. I
am not able to locate such elements using an XPath expression. I tried
the following:

//*[@msg="Hello "World", What's up"]
Failes with string error at double quote before World

//*[@msg='Hello "World", What's up']
Failes with string error at single quote after What

//*[@msg="Hello "World", What's up"]
I used the escpase sequence for double quote in my xpath which you are
seeing as acutal double quote in this post.
No Error but does not return any node.

//*[@msg="Hello "World", What's up"]
I used the escpase sequence for both double quotes and single quotes in
my xpath which you are seeing as acutal double quote and single quotesin
this post
No Error but does not return any node

I tried both MSXML 3.0 and MSXML 4.
Any Ideas??

&quot; is your friend.

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top