Groups | Blog | Home
all groups > dotnet xml > october 2005 >

dotnet xml : xpath when quotes are in node


David Thielen
10/13/2005 9:24:34 PM
I have the following xml:

<root>
<name>abc "123" xyz</name>
</root>

When I get an XPathNavigator to root and then call navigator.Evaluate("name
= \"abc \\\"123\\\" xyz"), I get an XPathException. I also tried \\" and " -
all throw an exception.

How am I supposed to handle this?

--
Martin Honnen
10/14/2005 12:00:00 AM


[quoted text, click to view]

XPath allows both ' and " as the delimiters to string literals so in C#
a string literal like
"name = 'abc \"123\" xyz'"
should do, the outer " delimits the C#/.NET string, the ' delimits the
XPath string and \" is necessary to escape the double quote in the C#
string literal.

But there can be ugly situations with both ' and " used where you need
to split strings and use concat to build your XPath expression in a
syntactically correct way.


--

Martin Honnen --- MVP XML
Martin Honnen
10/14/2005 12:00:00 AM

[quoted text, click to view]

As an escape mechanism? No, at least in XPath 1.0 there is no such
escape. You can use ' and " but there is no escape character.
And if the XPath is used inside of an XML document (e.g. an XSLT
stylesheet) then you can use the XML escape mechanisms e.g. &quot;
<xsl:value-of select="&quot;Kibology&quot;" />


--

Martin Honnen --- MVP XML
David Thielen
10/14/2005 6:43:01 AM
Hello;

But isn't \" an official part of xpath?

My problem is that the xpath statements come from xml so we have <node
attr='xpath'/> and so the xpath is "abc \\\"123\\\" xyz" making an actual
node of.

This works fine in java (dom4j/jaxen) and I assumed this is standard???

--
thanks - dave


[quoted text, click to view]
David Thielen
10/14/2005 9:23:04 AM
Yuck - ok - thanks


--
thanks - dave


[quoted text, click to view]
AddThis Social Bookmark Button