Thanks for the link. I read through the spec and found this to be helpful:
"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 (" or '). Alternatively, the
expression can use single quotation marks if the XML attribute is delimited
with double quotation marks or vice-versa."
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.
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 (" or '). 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' />
A better way is to escape using a built in entity reference:
" - to produce the " character
' - to produce the ' character
> 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.
Greg - 29 Dec 2004 19:16 GMT
> Hi Greg:
>
[quoted text clipped - 13 lines]
> (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:
>
> " - to produce the " character
> ' - 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"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
[quoted text clipped - 4 lines]
> an XML Document as specified by the XML DOM. It does not need to store
> attribute enclosed within quotes.
> Thanks,
> Mujtaba.