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.
0
7/18/2008 3:49:52 AM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
593 Views

Similar Articles

[PageSpeed] 57

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/
0
mahotrash (1778)
7/18/2008 11:09:18 AM
On Fri, 18 Jul 2008 13:09:18 +0200, Martin Honnen <mahotrash@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?
0
7/18/2008 3:23:37 PM
Alan Mailer wrote:
> On Fri, 18 Jul 2008 13:09:18 +0200, Martin Honnen <mahotrash@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/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."


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
7/18/2008 4:29:56 PM
Reply:

Similar Artilces:

XML Custom serialization
Hi all, I want to serialize a class in a customized way. But I don't want to implement the ISerializable interafce because I don't want to take care of every new field I insert to the class. What I need is a way to customize the serialization of a specific field in my class but leave the rest to the build-in serialization. Any guidance will be appreciated. Ro'ee <sfa.roy@gmail.com> wrote in message news:7243a1eb-3fa3-43e0-8339-d90f890e6716@b1g2000hsg.googlegroups.com... > Hi all, > > I want to serialize a class in a customized way. But I don't want to >...

Help: Macro that runs various if statements, inserting rows etc
I am a newcomer to Macros and excel programming and was hoping someone could assist / provide the code to do the following: I have a +50,000 line spreadsheet, that needs to be formatted. Given the size I would like to automate this. There are 3 key formatting changes required and detailed below: n = 1 1. If Cell A(n) not equal Cell A(n+1) then insert a new row below A(n), make Cell F(insertedrow)=1, make Cell G(insertedrow)=A(n+1), make Cell H(insertedrow)=B(n+1) 2. If Cell C(n) not equal Cell C(n+1) then insert a new row below C(n), make Cell F(insertedrow)=2, make Cell G(inserte...

Is there a way for Windows Service to Read/Write HKCU Reg key ?
Hi: I'm writing a Windows Service program which needs to read/write the HKEY_CURRENT_USER registry key for the current logged on user. I know that for a Windows service does not have concept of HKCU since it is always running in SYSTEM's context. But is there a way (trick?) for a service to access the HKCU registry key? Thanks In Advance ! Polaris Hello Try, from a user application (the one that is logged on, or the current user), to send the services the user's SID. Then access the HKCU through HKEY_USERS\users_sid\............ Hope that helps, Elias "Polaris&qu...

Write
I am trying to change the default margins. I am requested to use the Write mode to do this. What is Write, and how do I access it? Are you using voice recognition? Margins are simply changed in the Arrange Menu in Publisher. Are you in the right newsgroup? -- Mary Sauer MS MVP http://office.microsoft.com/ http://www.mvps.org/msauer/ news://msnews.microsoft.com "CBC" <anonymous@discussions.microsoft.com> wrote in message news:183bb01c44a40$107bd5d0$a501280a@phx.gbl... > I am trying to change the default margins. I am requested > to use the Write mode to do this. W...

get a result of an sql statement in a field ?
Hi there I have an Excel sheet with many lines of data. I would like to know if there is a possibilty to create a field which will execute an sql-statment on an MSsql Database and will return the result. Some thing like (select name from address where uid=$B5) Thanks in advance for any help Ralf I found out that the statement sql.request should do it. But where can I find the addin for Excel 2003 Thanks in advance Ralf "Ralf Meuser" <rmeuser@free.fr> a �crit dans le message de news:40c85d65$0$26917$626a14ce@news.free.fr... > Hi there > > I have an Excel she...

CSV to XML, now to validate
hiya, I have a 3rd party function that converts a CSV to an XML doc. I now need to validate the xmlDoc.I understand that I need a valid XSD for the newly created xmlDoc, but the xmlDoc contains no schema definitions etc.I'm not sure how to create an XSD, so that the fields are restricted to "integer" datatypes etc. Been looking for a while.I assume that I don't have to manually write an XSD?maybe I should create a "dummy" table in sqlServer, then generate a dataset to get the XSD?Or, maybe vis studio 2003 has tools to make this easier? Any suggestions appreciated...

RMS Statements
How do you get the current date to print on a statement? ...

Writing formula for excel worksheet
Item Rate1 Rate2 Rate3 A 3 4 6 B 8 5 23 C 56 5 78 Above is my excel sheet. I want to write some formula so that in every row cell having minimum rate should come bold. Like For Item A - Rate1(3) for Item B - Rate2(5) For Item C - Rate2 (5) There may be a neater way but this works. Somewhere in you sheet in a cell type =min(A1:a4), I used L1 Change this to watever range you are trying to evaluate. Then select this range and click format - conditional format - cell value - is equal to =($L$1) and apply your bold font. The lowest value in the range will then become bold. Mike "Gaur...

RW Error in GP 10 Modified Account Statement
I have modified the Account Statement to bring in the RM Tax Work table to display GST for each invoice. When I run report from GP, I get: 'Inconsistent restriction/sort expression. Please add the following restriction 'calc20009 = calc20009.' I did add a restriction with 2 strings to do this, but error doesn't go away. Help. Tx Les Figured it out by restricting number of records coming in from 1 to many table.. then saw this in KB: https://mbs.microsoft.com/knowledgebase/KBDisplay.aspx?WTNTZSMNWUKNTMMYVTQUUXNNZOUKYPPPNUXLNZQRYMOKTVQUMUULVKYNOXRKNNKXOYQQROXLKLMYZPOWQKLKQ...

write protect/write redirect/kios mode
Hey, I LOVE snapshots in virtualmachines and think it would be awesome to have something like this for my main windows install. Anyone know of any hardware/software to redirect writes to another drive/file/memory/hardware? Or hardware to write protect a drive for kios's (i found some once befor the reverted all changes on shutdown, but cant find it anymore ><) I know VSS(virtual shadow copy service) has a function to redirect on write and wondering if i might be able to use that :/ It will just make everything cleaner, and give alot of flexiblity to setting up ...

Cannot write to memory location
I can not (all of the sudden) run Publisher in the last week. When starting to run it, I get that it cannot write to a certain memory locaiton, so it is shutting down. I need to get this program working. I have read through this forum and tried the different fixes as well as the knowledge base (emptied the temp file, disabled anti-virus, etc.) but it still won't work. An example is: "The instruction at "0x77f585c0" referenced memory at "0x00000000". the memory could not be "written". Click on OK to terminate the program." The header read...

XSLT: Creating anchors from outer XML files
Hi, I'm trying to put the links (href attribute of the <a> element) out of my XSLT files, in a XML file, and read it from the stylesheet. I suppose that I have to use the document() function to link to the XML file containing the URLs, but I don't know how to do it. I've tried something like this: This is XML file containing the URLs (link.xml): <?xml version="1.0" encoding="utf-8" ?> <LINKS> <L1> /SomePage.aspx </L1> </LINKS> And this is the code from the stylesheet: <a href="{document('link.xml')/L...

how do i write checkbox to.....
This is a multi-part message in MIME format. --------------050607000103070200020407 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit how do i write checkbox1 boolean to xml in vb6 i can only do cstr( checkbox1.value) but in vb.net can't write to xml. i am doing irc chat similar to mirc or pirch chat. rw.WriteConfigInfo("User Modes", chkInvisible.Text, chkInvisible.Checked, "PirateChat.xml") in procedure events: ' Both the Key and the Value are filled ' Find the key ...

xml to flat file
Hi. Is there any way of using an xml schema file to a. validate the xml data then writing the xml out as a flat flat. For example in the schema it would say the element has a maximum length of 10 characters and therefore when it is written out as text the value is 10 characters ? <field1>hello</field1> <field2>all</field2> flat file would be hello_____all thanks ...

Combo Box/SQL statement
I have a combo box whose Row Source Type is table/query and Row Source is "SELECT DISTINCT [Package Name] from Packages ORDER BY [Package Name];". I can see the values when I run that SQL statement as a query, but nothing shows up when I run it as a function of the form (i.e., the form opens up, the SQL statement runs, but nothing shows up in the combo box). I mean literally, nothing shows up, although I can see there are the three place holders in the list I'm expecting, but no text. I'm wondering how much effect the Bound Column property has on this, and frankly, from th...

Extend the XML Schema via C# objects
I have C# objects/entities (like person or customer) which contains the usual amount properties/attributes like name, address and so on.. I would like to "tag" some of these properties, so that when I'm generating and XML Schema (via Wsdl for instance) the tags are displayed in the Schema portion of the Wsdl. Something like the following snippet: <?xml version="1.0" encoding="utf-8"?> <xs:scheme attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" ...

Write access to a LDAP server.
Is there any way to enable write access in Outlook to my LDAP server? The LDAP server allows this functionality, Outlook doesn't. Any plugins that can do this? Thanks. Derek ...

xml and updategram
I have been searching for quite a while for an example of how to use javascript and xml dom to create updategrams and to send them back to my sql server. I have a webpage where I use javascript to add, edit or delete rows from an <xml> object. I can load it from sql server. I cannot find out how to use updategrams to get it back to the sql server. I would appreciate being pointed to an example. thank you mark ...

Writing a macro in Outlook 2007
Hello - I have been trying to create code in Outlook 2007 that will send an item to a specific printer. I realize there is no macro recorder in Outlook, and I am not a programmer, so I've been trying to manipulate code found on a Microsoft support page, without success. Does anyone know the code required to send an item to a specific printer, other than the default? Here is a sample of what I've found - it includes resetting the default printer: Sub MAIN 'Retrieve and set information about the current default printer Dim FPS As FilePrintSetup GetCurValues FPS ...

MULTI STORE ORDER WRITING-SIMPLIFY
Hi- We have 7 stores and need to simplify the order writing process. Is there any way to write POs for all of our stores without having to do each order separately? We would like for all orders to come up with the items we want to order, being able to change the quantities according to the store. Thank you in advance for your help. This is a multi-part message in MIME format. ------=_NextPart_000_0599_01C6CAFF.B4705610 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable J, Have you tried the 340 PO Planner worksheet? --=20 * Get Secure! - ...

XML Application
We use xml files to denote file configurations for our company. We are now getting to the point where need a browser based method of maintaining and creating the configuration files. I had written a small test app for working with XML in ASP.Net and have found that it is painfully slow and cumbersome. Can anyone give me some suggestions or sample links to articles that would help develop an application of this type? I need to allow the user to create a new configuration xml document and modify them with the usual updates, inserts and deletes of nodes. Thanks, Matt ...

how to write a formula
I have just taken over as manager of a boarding house and need to come up with some formulas to allow me to enter a dollar amount in cells c1:c12 and then have excel convert that to a day value( 1 day = 13.57) , it then needs to take the date in cells d1:d12 add the reultant conversion and place the result in cells e1:e12 as a date in real time ( 23/05/205). Also is it possible to get excell to print out a receipt for each entry that is made. I have never used excell and currently do it manually with Word which is hard and long In E1, just enter =D1+(C1/13.57), format as date and copy...

Financial Statements.xls
I have purchased the ebook "financial statements.xls" and am goin through the process of settin up the model. I have come across a name range, "BS_Level", that is referred to in the formul "=INDEX((BS_Level,MATCH(C2,Level3,0),2)" that is not listed in the se up. i haev no idea what this range should be. I searched the eboo and had no hits beyond the formula listed above. Please advise as love the potential of this file -- Message posted from http://www.ExcelForum.com I'll bet you could have found a free template somewhere on the web. Level3 is a proba...

writing on an excel file
my employer emailed me an expense report and i downloaded excel. i can't seem to write on this document. is it because its a read only fiel? how do i convert it to be able to edit and write in my expenxes? HELP!!!!!! is it because it's read only ? - check with properties under explorer. either change it there, or save as a different name Steve On Sat, 02 Sep 2006 18:06:02 +0100, RITZ <RITZ@discussions.microsoft.com= > = wrote: > my employer emailed me an expense report and i downloaded excel. i can= 't = > seem > to write on this document. is it because i...

Apostrophe Mark
Can anyone defien me the differnce between [Forms].[frm1] and [Forms]![frm1] when we use a "." and when "!" Abdul, AFAIK no-one says this better than Dirk Goldgar, as follows... -------------------------------------- "It's not so much a question of one or the other being "proper syntax", but that they mean different things that nevertheless almost always give the same result. As I understand it, the bang (!) notation specifically denotes that what follows is a member of a collection; in this case, a member of the form object's default col...