473,372 Members | 802 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,372 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 7988
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.