Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alan Mailer - 18 Jul 2008 04:49 GMT
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.
Martin Honnen - 18 Jul 2008 12:09 GMT
> myXmlNodeList =
> MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title='Joe's
[quoted text clipped - 5 lines]
> 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.

Signature

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

Alan Mailer - 18 Jul 2008 16:23 GMT
>> myXmlNodeList =
>> MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title='Joe's
[quoted text clipped - 11 lines]
>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?
Martin Honnen - 18 Jul 2008 17:29 GMT
>>> myXmlNodeList =
>>> MyXmlDoc.SelectNodes("MyParentNode/SomeOtherNode[Title='Joe's
[quoted text clipped - 28 lines]
> ...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/library/thwcx436(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."

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.