Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Thu, 08 May 2008 16:02:15 +0100,    group: microsoft.public.xml        back       


XPath SelectSingleNode query with quotes problem.   
I've got a problem reading in and searching through data where the
attributes might contain both single and/or double quotes. As they get
inserted into an XmlDocument, they get marked up with " and
' properly (which I can tell by looking at OuterXML), but then
using xPath to search for them is proving to be inconsistent. It's
like I can only write code that works for either double or single
quotes at time, depending on what I use to surround the data in the
query in the first place. All would be fine if using marked up code in
my queries worked, but it doesn't. So anyone know why this code
doesn't work:

XmlDocument xd = new XmlDocument();
XmlElement xe = xd.CreateElement("Element");
xe.SetAttribute("Attr", "Hello 'world'");
xd.AppendChild(xe);

xd.SelectSingleNode("//Element[@Attr=\"Hello 'world'\"]");
xd.SelectSingleNode("//Element[@Attr=\"Hello 'world'\"]");


The first select works fine, but the second one fails. I'm led to
believe that they're a direct equivalent, so what's happening here?

Thanks for any help!
date: Thu, 08 May 2008 16:02:15 +0100   author:   Minerva Jones et

Re: XPath SelectSingleNode query with quotes problem.   
Minerva Jones wrote:
> I've got a problem reading in and searching through data where the
> attributes might contain both single and/or double quotes. As they get
> inserted into an XmlDocument, they get marked up with " and
> ' properly (which I can tell by looking at OuterXML), but then
> using xPath to search for them is proving to be inconsistent. It's
> like I can only write code that works for either double or single
> quotes at time, depending on what I use to surround the data in the
> query in the first place. 

If you need both single and double quote in a string literal then you 
have two choices, either implement variables or split the string into 
sections where you use single and double quotes e.g.
   concat("Hello 'Word', Hello ", '"Word"')

I think http://www.codeplex.com/Wiki/View.aspx?ProjectName=MVPXML 
provides variable resolution.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Thu, 08 May 2008 17:47:48 +0200   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us