473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 7983
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kevin Conroy | last post by:
I'm making a 6-tiered application that is using Xml to tie the various layers together in a very clean manner. I'm also trying to do this on the 1.1 Framework although I'm willing to switch to the...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
2
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
4
by: BuddyWork | last post by:
Hello, When running the following line of code XmlSerializer serializer = new XmlSerializer(typeof (MyXmlTestClass)); I get the following exception message. An unhandled exception of
1
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
0
by: PSingh | last post by:
Hi, I know this is a frequently asked question but have tried several combinations and cant seem to figure this out. I am serializing my object as follows: XmlSerializer serializer = new...
6
by: Andrew | last post by:
I am using an XmlSerializer to save some settings and I have discovered that when a string is saved containing a cr+nl it is replaced with just a newline when loading back in. I am no expert with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.