Re: How do I escape single tick marks in XPath Queries?

From: Greg (na)
Date: 12/29/04


Date: Wed, 29 Dec 2004 14:16:06 -0500


"Mujtaba Syed" <mujtaba@marlabs.com> wrote in message
news:%232LFI1b7EHA.3944@TK2MSFTNGP12.phx.gbl...
> Hi Greg:
>
> > "To avoid a quotation mark in an expression being interpreted by the XML
> > processor as terminating the attribute value the quotation mark can be
> > entered as a character reference (&quot; or &apos;). Alternatively, the
> > expression can use single quotation marks if the XML attribute is
> delimited
> > with double quotation marks or vice-versa."
>
> A well formed XML document should have all its attributes enclosed within
> matching quotes, either single (') or double (").
> So, <root val='Greg' /> and <root val="Greg" /> are well-formed while
<root
> val='Greg" /> and <root val="Greg' /> and <root val=Greg /> are not.
>
> If you have single or double quotes are part of an attribute's value
> (PCDATA), you could use the alternate quote to enclose attributes.
> Ex, <root val="Greg's car" /> and <root val='Greg's car' />

If you read the recommendation paragraph quote (earlier in this thread)
you'll see that a tick mark is not valid in an attribute unless it is
enclosed with double qoutes (ie "Greg's car" is valid, while 'Greg's car'
is not). Interestingly, if I try doing something like

"Greg's car" is great as the attribute , the XML Dom tells me I have an
invalid character when I try to load the doucment. In other words, double
quotes are not valid inside an attribute, but single quotes are. If I am
using single quotes in my XPath query as the beginning/ending expression, I
get an error if a single quote exists in my query. I find this behavior a
little inconsistent in the DOM and that was more my gripe than anything.

>
> A better way is to escape using a built in entity reference:
>
> &quot; - to produce the " character
> &apos; - to produce the ' character

This is true, BUT you will still have to do the decoding / encoding
manually. In other words, if I want to search for "Greg's car" with XPath, I
would have to convert my query to Greg&quot;s Car first. I was simply
saying that it would be nice if this conversion could be done automatically
by the DOM. Of course, it may work fine in my situation, but there are
probably other situations that it wouldn't work all that great for...

>
> > Interestingly, the XmlDocument object is letting me put whatever I want
in
> > an attribute, including tick marks and double quotes. It'd be nice to
see
> > it auto encode / decode since those aren't legal characters, or better
yet
> > an exception thrown if I try to put them in.
>
> The XMLDocument is a framework type that is the in-memory representation
of
> an XML Document as specified by the XML DOM. It does not need to store
> attribute enclosed within quotes.

>
> Thanks,
> Mujtaba.
>
>



Relevant Pages

  • Re: How do I escape single tick marks in XPath Queries?
    ... > processor as terminating the attribute value the quotation mark can be ... A well formed XML document should have all its attributes enclosed within ... If you have single or double quotes are part of an attribute's value ... you could use the alternate quote to enclose attributes. ...
    (microsoft.public.dotnet.xml)
  • Re: Deserialization issue
    ... In the real file the quotes were present. ... The publisher didn't publish the schema. ... the xml document: "The same table cannot be the child table ... >> class SomeObject ...
    (microsoft.public.dotnet.xml)
  • Re: How can I ensure that I always have a list?
    ... tdom is an XML parsing extension for Tcl. ... # Match one tag. ... # quotes, ... # key/value pair) for further processing the next time we go ...
    (comp.lang.tcl)
  • Re: How can I ensure that I always have a list?
    ... tdom is an XML parsing extension for Tcl. ... # Match one tag. ... # quotes, ... # key/value pair) for further processing the next time we go ...
    (comp.lang.tcl)
  • Re: VBScript and quotes within command line parameters
    ... should be sent to your script as one arg with the quotes where they belong. ... Microsoft uses Microsoft C Runtime for C ... interpreted as a literal double quotation mark. ...
    (microsoft.public.scripting.vbscript)

Loading