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

How to write APOSTROPHE into an XML SelectNodes statement????

Ok, I've looked for an answer for this, because I'm sure it's been
asked a thousand times... but no luck... so here goes.

Imagine I want to create a NodeList based on an XPath statement. The
'query' portion of that statement wants to search for the following
value:

Joe's Garage

....now please note the APOSTROPHE in the above string.

Now, you VB.Net & XML experts know the following will NOT work:

myXmlNodeList =
MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title='Joe's
Garage'])

....because the *apostrophe* in "Joe's" will screw the statement up and
cause an error to be triggered.

So... precisely how would you experts write the above SelectNodes
statement so that VB.Net would NOT trigger a darn error?

Thanks in advance for your help.
Jul 18 '08 #1
3 6794
Alan Mailer wrote:
myXmlNodeList =
MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title='Joe's
Garage'])

...because the *apostrophe* in "Joe's" will screw the statement up and
cause an error to be triggered.

So... precisely how would you experts write the above SelectNodes
statement so that VB.Net would NOT trigger a darn error?
MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title=""Joe's
Garage""]")

should do. It only gets complicated if you need to use a double quote
and a single quote together in the string literal.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 18 '08 #2
On Fri, 18 Jul 2008 13:09:18 +0200, Martin Honnen <ma*******@yahoo.de>
wrote:
>Alan Mailer wrote:
>myXmlNodeList =
MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title='Joe's
Garage'])

...because the *apostrophe* in "Joe's" will screw the statement up and
cause an error to be triggered.

So... precisely how would you experts write the above SelectNodes
statement so that VB.Net would NOT trigger a darn error?

MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title=""Joe's
Garage""]")

should do. It only gets complicated if you need to use a double quote
and a single quote together in the string literal.
Martin, thanks for responding. It's a little hard to read your
suggestion, so I'm going to parse it here and hope you'll let me know
if I'm reading it correctly. Parsed out, your SelectNodes statement
is written as follows:

Double Quotes
MyParentNode/SomeOtherNode[Title=
Double Quotes
Double Quotes
Joe's Garage
Double Quotes
Double Quotes
]
Double Quotes

....If you have a moment to handle this follow-up question, I'd really
appreciate it. Have I read your suggestion correctly?
Jul 18 '08 #3
Alan Mailer wrote:
On Fri, 18 Jul 2008 13:09:18 +0200, Martin Honnen <ma*******@yahoo.de>
wrote:
>Alan Mailer wrote:
>>myXmlNodeList =
MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title='Joe's
Garage'])

...because the *apostrophe* in "Joe's" will screw the statement up and
cause an error to be triggered.

So... precisely how would you experts write the above SelectNodes
statement so that VB.Net would NOT trigger a darn error?
MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title=""Joe's
Garage""]")

should do. It only gets complicated if you need to use a double quote
and a single quote together in the string literal.

Martin, thanks for responding. It's a little hard to read your
suggestion, so I'm going to parse it here and hope you'll let me know
if I'm reading it correctly. Parsed out, your SelectNodes statement
is written as follows:

Double Quotes
MyParentNode/SomeOtherNode[Title=
Double Quotes
Double Quotes
Joe's Garage
Double Quotes
Double Quotes
]
Double Quotes

...If you have a moment to handle this follow-up question, I'd really
appreciate it. Have I read your suggestion correctly?
Yes, with VB if you want to include a double quote inside a string
literal then you need to double the double quote, see
http://msdn.microsoft.com/en-us/libr...36(VS.80).aspx
where it says:
You must enclose a String literal within quotation marks (" "). If you
need to include a quotation mark as one of the characters in the string,
you use two contiguous quotation marks (""). The following example
illustrates this.
Dim j As String = "Joe said ""Hello"" to me."
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 18 '08 #4

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

Similar topics

15
by: middletree | last post by:
Ray recently answered my question about apostrophe replacement with advice on how to use 2 functions for hwich he gave me some code, called SafeIn and Safeout I'm having a hard time seeing the...
1
by: Joel | last post by:
I realize there are many ways to handle Apostrophes in sql statements. The problem I'm having is comparing a string with an Apostrophe entered by the operator against the field in the DB (ie Field:...
3
by: Peter Choe | last post by:
i am trying to add a record of a name. the name has an apostrophe (O'Neil). i am doing this through a servlet and wrote the code to use PreparedStatement. when i do: .... PrepareStatement...
13
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices...
1
by: spacehopper_man | last post by:
hi - I am having "apostrophe in sql" problems ;) I am executing a stored procedure on SQL Server - and passing in a string parameter. the string has a single apostrophe in it. the call...
0
sashi
by: sashi | last post by:
Apostrophe Have you ever tried to send a string variable to MS Access that had apostrophes embedded within an SQL Statement? If YES you will get a run time ERROR. Here is your solution, a function...
12
by: Johnny BeGood | last post by:
Hi All, When a user enters an Apostrophe into a text area field on a form, i.e. didn't, it mucks with odbc as follows Syntax error (missing operator) in query expression ''didn't', Whats...
9
by: Thomas 'PointedEars' Lahn | last post by:
Jukka K. Korpela wrote: IBTD. For example, in English it is customary (and AIUI expected) to use the character that ’ represents should be used to delimit a quotation within direct speech...
10
by: Path9898 | last post by:
greetings. I am having an issue with a piece of code, I was hoping someone can show me where I am going wrong. Basically I select 9 rows of data out of a table that have the same item number, but...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.