Using quotes in Xpath

Tell me if I need to use XPath expression as follows

v:MapLink[@Entity='TOM RESTAURANT']

But the exception is thrown due to a quote in TOM'S.

Is there any way around this?

Thank.

+3
source share
5 answers

presumably this is all inside the line itself, so will this work?

"v:MapLink[@Entity=\"TOM RESTAURANT\"]"
+4
source

Just use different quotes around the attribute:

v:MapLink[@Entity="TOM RESTAURANT"]
+2
source

"" ( ) XPath, .

If you have a literal containing both, you can use the function concat()as follows:

Tom "Napoli" Pizza

as the letter in the XPath expression will become

concat("Tom ", '"Napoli" Pizza')
+2
source

All of the above; plus, in XPath 2.0 you can use the SQL convention for doubling quotation marks. So you can write

"Tom ""Nopoli"" Pizza"
+1
source

In my case, for example, the XPath search element in 2 Forms:

(1) Parameters/Parameter[Key="{0}"]

(2) Parameters/Parameter[Key='{0}']

When {0} = CCC[AAA="BBB"]DDD

The first form will receive an error, and the second form, which makes the quotation marks "," different, will work.

it

// All using " Get Error
Parameters/Parameter[Key="CCC[AAA="BBB"]DDD"] 

// Using ' Out,  and " In  Work
Parameters/Parameter[Key='CCC[AAA="BBB"]DDD'] 
0
source

All Articles