473,387 Members | 1,529 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,387 software developers and data experts.

How to escape single quotes

I've scoured google, but apparently none of the suggestions actually work.

I have the following. type of XPATH query

"SomeNode[SomeAttribute = 'abc's search'"

Now, I've tried doing this:

"SomeNode[SomeAttribute = 'abc@apos;s search'"

and I've tried

"SomeNode[SomeAttribute = 'abc@quot;s search'"

And neither one of these gives me a result.

Note, because of the structure and the way this XPATH is put together, I
would prefer to not have to use double quotes as the delimiters for the
search string, I'd like to keep it single quotes.

How to make this query find my node?
Nov 13 '06 #1
8 21456
Marina Levit [MVP] wrote:
I've scoured google, but apparently none of the suggestions actually work.

I have the following. type of XPATH query

"SomeNode[SomeAttribute = 'abc's search'"

Now, I've tried doing this:

"SomeNode[SomeAttribute = 'abc@apos;s search'"
Assuming you actually meant '...

<xsl:variable name="apos">
<xsl:text>'</xsl:text>
</xsl:variable>
<xsl:if test="SomeNode[SomeAttribute = concat('abc',$apos,'s search')]">
....

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Nov 13 '06 #2
But I have an XPATH expression and I am searching for a node. How does what
you wrote fit into that?

"Peter Flynn" <pe********@m.silmaril.iewrote in message
news:4r************@mid.individual.net...
Marina Levit [MVP] wrote:
>I've scoured google, but apparently none of the suggestions actually
work.

I have the following. type of XPATH query

"SomeNode[SomeAttribute = 'abc's search'"

Now, I've tried doing this:

"SomeNode[SomeAttribute = 'abc@apos;s search'"

Assuming you actually meant &apos;...

<xsl:variable name="apos">
<xsl:text>'</xsl:text>
</xsl:variable>
<xsl:if test="SomeNode[SomeAttribute = concat('abc',$apos,'s search')]">
...

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Nov 14 '06 #3
Marina Levit [MVP] wrote:
I've scoured google, but apparently none of the suggestions actually work.

I have the following. type of XPATH query

"SomeNode[SomeAttribute = 'abc's search'"

Now, I've tried doing this:

"SomeNode[SomeAttribute = 'abc@apos;s search'"

and I've tried

"SomeNode[SomeAttribute = 'abc@quot;s search'"

And neither one of these gives me a result.

Note, because of the structure and the way this XPATH is put together, I
would prefer to not have to use double quotes as the delimiters for the
search string, I'd like to keep it single quotes.

How to make this query find my node?
In what context are you using the XPath? If that is an XSLT stylesheet
then using entity references like &apos; or &quot; might help but if you
have .NET code (e.g. C# or VB.NET) then using those XML entity
references is not possible.
As for that escape problem, it is ugly, XPath 1.0 itself does not have
any escape mechanism so you need to split strings e.g. C# string literal
to be passed to SelectSingleNode looks like
@"SomeNode[@SomeAttribute = concat('abc', ""'"", 's search')]"

See also Oleg's blog
<http://www.tkachenko.com/blog/archives/000627.htmlrespectively the
XPathCache API the MVP XML project provides.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 14 '06 #4
Oy... what a headache.

The problem with this approach is that I can't just escape the characters.
There is a ton of code that already assumes there are single quote
delimiters to the search string. All that would have to be changed.

Using the jscript XML object model this all works without a problem. And
yet, .NET can't implement an XML DOM that works half way decent.

Thanks

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:e%****************@TK2MSFTNGP03.phx.gbl...
Marina Levit [MVP] wrote:
>I've scoured google, but apparently none of the suggestions actually
work.

I have the following. type of XPATH query

"SomeNode[SomeAttribute = 'abc's search'"

Now, I've tried doing this:

"SomeNode[SomeAttribute = 'abc@apos;s search'"

and I've tried

"SomeNode[SomeAttribute = 'abc@quot;s search'"

And neither one of these gives me a result.

Note, because of the structure and the way this XPATH is put together, I
would prefer to not have to use double quotes as the delimiters for the
search string, I'd like to keep it single quotes.

How to make this query find my node?

In what context are you using the XPath? If that is an XSLT stylesheet
then using entity references like &apos; or &quot; might help but if you
have .NET code (e.g. C# or VB.NET) then using those XML entity references
is not possible.
As for that escape problem, it is ugly, XPath 1.0 itself does not have any
escape mechanism so you need to split strings e.g. C# string literal to be
passed to SelectSingleNode looks like
@"SomeNode[@SomeAttribute = concat('abc', ""'"", 's search')]"

See also Oleg's blog
<http://www.tkachenko.com/blog/archives/000627.htmlrespectively the
XPathCache API the MVP XML project provides.

--

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

Nov 14 '06 #5
Marina Levit [MVP] wrote:
Using the jscript XML object model this all works without a problem. And
yet, .NET can't implement an XML DOM that works half way decent.
I am not sure why you think it is a .NET issue. What exactly are you
doing with JScript and MSXML that you can't do with .NET and C# (or VB.NET)?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 14 '06 #6
Querying a dom to locate certain nodes where a string literal has a single
quote in it.

This works perfectly in MSXML, as apparently that uses an XSL pattern query
(not that I really know exactly what that is), which is apparently more
flexible, and allows this to actually work.

..NET follows the XPATH 1.0 standard, which apparently isn't as useful,
meaning I can't have single quotes in literals when searching for nodes in a
DOM.

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:eF****************@TK2MSFTNGP03.phx.gbl...
Marina Levit [MVP] wrote:
>Using the jscript XML object model this all works without a problem. And
yet, .NET can't implement an XML DOM that works half way decent.

I am not sure why you think it is a .NET issue. What exactly are you doing
with JScript and MSXML that you can't do with .NET and C# (or VB.NET)?

--

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

Nov 14 '06 #7
Marina Levit [MVP] wrote:
But I have an XPATH expression and I am searching for a node. How does what
you wrote fit into that?
What I wrote. I just copied your sample XPath expression.
I'm not sure I understand what the difficulty is.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

"Peter Flynn" <pe********@m.silmaril.iewrote in message
news:4r************@mid.individual.net...
>Marina Levit [MVP] wrote:
>>I've scoured google, but apparently none of the suggestions actually
work.

I have the following. type of XPATH query

"SomeNode[SomeAttribute = 'abc's search'"

Now, I've tried doing this:

"SomeNode[SomeAttribute = 'abc@apos;s search'"
Assuming you actually meant &apos;...

<xsl:variable name="apos">
<xsl:text>'</xsl:text>
</xsl:variable>
<xsl:if test="SomeNode[SomeAttribute = concat('abc',$apos,'s search')]">
...

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Nov 14 '06 #8
You want me to use the XSL as an XPATH expression?

I think concat on its own works fine. The problem is, like I said, I didn't
want to have to change the delimiters which are single quotes everywhere.
Which I would have to do, so the concat doesn't end up as a literal.

I expected to be able to do a replace in the search string to escape the
single quotes, so single quotes can remain the delimiters for the literal.

"Peter Flynn" <pe********@m.silmaril.iewrote in message
news:4r************@mid.individual.net...
Marina Levit [MVP] wrote:
>But I have an XPATH expression and I am searching for a node. How does
what you wrote fit into that?

What I wrote. I just copied your sample XPath expression.
I'm not sure I understand what the difficulty is.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

>"Peter Flynn" <pe********@m.silmaril.iewrote in message
news:4r************@mid.individual.net...
>>Marina Levit [MVP] wrote:
I've scoured google, but apparently none of the suggestions actually
work.

I have the following. type of XPATH query

"SomeNode[SomeAttribute = 'abc's search'"

Now, I've tried doing this:

"SomeNode[SomeAttribute = 'abc@apos;s search'"
Assuming you actually meant &apos;...

<xsl:variable name="apos">
<xsl:text>'</xsl:text>
</xsl:variable>
<xsl:if test="SomeNode[SomeAttribute = concat('abc',$apos,'s search')]">
...

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Nov 15 '06 #9

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

Similar topics

3
by: TheKeith | last post by:
Hi, I'm just learning php now for the first time and I'm having a little trouble understanding something. In the following example: ...
7
by: Leif B. Kristensen | last post by:
I'm working with a Python program to insert / update textual data into a PostgreSQL database. The text has single and double quotes in it, and I wonder: What is the easiest way to escape quotes in...
1
by: JehanNYNJ | last post by:
I have to put some html into a variable like so.... var html = '<TABLE cellspacing="5" border="0" ....... But within this html string I also need to have the code for a button that traps the...
4
by: Greg | last post by:
I keep getting an error when I have a tick mark in a text value that I am searching for in my XPath Query. Example: <Authors> <Author LastName="O'Donnel"> <Author LastName="Smith">...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
7
by: Axel Dahmen | last post by:
Hi, within a DataGrid control I'm using a DataTable containing a string column to fill a Hyperlink's href attribute. Unfortunately HttpUtility.UrlEncode() doesn't escape the apostroph character,...
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
10
by: Confused but working on it | last post by:
Hi all, I'm trying to do something simple and grabbed a snippet from the php manual for reading files in a directory. The snippet echos out a nice list of files. <?php //Open images directory...
1
by: crybaby | last post by:
I wrote a python code in linux text pad and copied to thumb drive and try to ran the file by changing the path to windows: sys.path = sys.path + I get the following error: ValueError:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.