469,283 Members | 2,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

XmlSerializer question

Hi,

I use XmlSerializer to serialize xml string. It escapes xml special
charaters, like < and > to < and >. How can I stop XmlSerializer to escape
these charaters?

Thanks in advance!!!
Cindy
Nov 12 '05 #1
3 7691
Cindy wrote:
I use XmlSerializer to serialize xml string. It escapes xml special
charaters, like < and > to < and >. How can I stop XmlSerializer to escape
these charaters?


If the XmlSerializer didn't escape the characters < and & (and for
compatibility >), then the result would not be well-formed XML. See section
2.4 of the XML specification [1]. Here's a portion of the spec:

"The ampersand character (&) and the left angle bracket (<) MUST NOT appear
in their literal form, except when used as markup delimiters, or within a
comment, a processing instruction, or a CDATA section. If they are needed
elsewhere, they MUST be escaped using either numeric character references or
the strings "&amp;" and "&lt;" respectively. ..."

Is there a reason you don't want to generate well-formed XML, or are you
trying to use the XmlSerializer to generate CDATA sections?

Cheers,
Stuart Celarier, Fern Creek

[1] http://www.w3.org/TR/2004/REC-xml-20040204/#syntax
Nov 12 '05 #2
Hi Stuart,

Because my data that is going to be serialized is also a well-formed xml.
After the serialization, it is not xml string anymore. Is there anyway I can
restore it to xml string in .Net? Do we have any class in .Net to perform the
functions, like escape and unescape in javascript?

Thanks,
Cindy

"Stuart Celarier" wrote:
Cindy wrote:
I use XmlSerializer to serialize xml string. It escapes xml special
charaters, like < and > to < and >. How can I stop XmlSerializer to escape
these charaters?


If the XmlSerializer didn't escape the characters < and & (and for
compatibility >), then the result would not be well-formed XML. See section
2.4 of the XML specification [1]. Here's a portion of the spec:

"The ampersand character (&) and the left angle bracket (<) MUST NOT appear
in their literal form, except when used as markup delimiters, or within a
comment, a processing instruction, or a CDATA section. If they are needed
elsewhere, they MUST be escaped using either numeric character references or
the strings "&" and "<" respectively. ..."

Is there a reason you don't want to generate well-formed XML, or are you
trying to use the XmlSerializer to generate CDATA sections?

Cheers,
Stuart Celarier, Fern Creek

[1] http://www.w3.org/TR/2004/REC-xml-20040204/#syntax

Nov 12 '05 #3
Seems like you are trying to serialise XML string as 'text'. There could be
a couple of things that go wrong, I made a mistake myself once when setting
an XML string as an InnerText instead of InnerXml.

Check the XML object 'before' serialisation, it probably has been encoded
there not during serialisation.

--
Victor Hadianto
http://synop.com/Products/SauceReader/
"Cindy Liu" <Ci******@discussions.microsoft.com> wrote in message
news:4A**********************************@microsof t.com...
Hi Stuart,

Because my data that is going to be serialized is also a well-formed xml.
After the serialization, it is not xml string anymore. Is there anyway I
can
restore it to xml string in .Net? Do we have any class in .Net to perform
the
functions, like escape and unescape in javascript?

Thanks,
Cindy

"Stuart Celarier" wrote:
Cindy wrote:
> I use XmlSerializer to serialize xml string. It escapes xml special
> charaters, like < and > to < and >. How can I stop XmlSerializer to
> escape
> these charaters?


If the XmlSerializer didn't escape the characters < and & (and for
compatibility >), then the result would not be well-formed XML. See
section
2.4 of the XML specification [1]. Here's a portion of the spec:

"The ampersand character (&) and the left angle bracket (<) MUST NOT
appear
in their literal form, except when used as markup delimiters, or within a
comment, a processing instruction, or a CDATA section. If they are needed
elsewhere, they MUST be escaped using either numeric character references
or
the strings "&" and "<" respectively. ..."

Is there a reason you don't want to generate well-formed XML, or are you
trying to use the XmlSerializer to generate CDATA sections?

Cheers,
Stuart Celarier, Fern Creek

[1] http://www.w3.org/TR/2004/REC-xml-20040204/#syntax

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Kevin Conroy | last post: by
4 posts views Thread by Andy Neilson | last post: by
2 posts views Thread by magister | last post: by
4 posts views Thread by BuddyWork | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.