473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

xpath when quotes are in node

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?

--
thanks - dave
Nov 12 '05 #1
4 1903


David Thielen wrote:
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.


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
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
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
"Martin Honnen" wrote:


David Thielen wrote:
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.


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
http://JavaScript.FAQTs.com/

Nov 12 '05 #3

David Thielen wrote:
But isn't \" an official part of xpath?


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
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
Yuck - ok - thanks
--
thanks - dave
"Martin Honnen" wrote:

David Thielen wrote:
But isn't \" an official part of xpath?


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. "
<xsl:value-of select=""Kibology"" />
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
3
by: Kevin | last post by:
I know this has probably been discussed many times before (I found answers when I searched yesterday), but I still can't get it to work... I have an attribute @OID that can contain any...
2
by: girish | last post by:
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...
4
by: gfrommer | last post by:
Hello everyone, I've been reading through a bunch of XPath tutorials and am confused by a couple items. First, is it possible to have multiple predicates in my XPath statement. For example, the...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
3
by: Jeff | last post by:
Hi all, I'm wondering if there is a function that will return the xpath to a specific node given its context node. Essentially, I want the reverse of the document.evaluate functionality. I've...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.