473,396 Members | 2,011 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,396 software developers and data experts.

XmlSerializer encoding and declaration issue

I am using XmlSerializer to serialize an object to xml string like the
following at C#. Now, I want to know how can I

1. change the default encoding to utf-8 or others, instead of utf-16
2. remove the XML declaration => <?xml version ....>
3. remove the white space / tab of the xml structure

XmlSerializer( typeof( PrinterSetting ) )

But, I got the something like the following:
<?xml version="1.0" encoding="utf-16"?>
<PrinterSetting xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PrinterName>aaaa</PrinterName>
<PaperSize>A4</PaperSize>
<IsDuplex>true</IsDuplex>
<NoOfCopies>2</NoOfCopies>
</PrinterSetting>
Nov 12 '05 #1
2 13520

inline

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:#B**************@TK2MSFTNGP09.phx.gbl...
I am using XmlSerializer to serialize an object to xml string like the
following at C#. Now, I want to know how can I

1. change the default encoding to utf-8 or others, instead of utf-16
If you write to a String you will always get utf-16. If you need utf-8 then
you need to write to stream like a MemoryStream or a FileStream.
2. remove the XML declaration => <?xml version ....>
Use my XmlFragmentWriter available at [0]
3. remove the white space / tab of the xml structure


Set the Formatting property of your XmlTextWriter to Formatting.None. This
should be the default though ...

[0]
http://www.gotdotnet.com/Community/U...b-3a0a9e13bbe3
Nov 12 '05 #2
thanks!

the class is exactly what i want.

cheers,
mullin

"Christoph Schittko [MVP]" <ch********************@austin.rr.com> wrote in
message news:eJ*************@tk2msftngp13.phx.gbl...

inline

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:#B**************@TK2MSFTNGP09.phx.gbl...
I am using XmlSerializer to serialize an object to xml string like the
following at C#. Now, I want to know how can I

1. change the default encoding to utf-8 or others, instead of utf-16
If you write to a String you will always get utf-16. If you need utf-8

then you need to write to stream like a MemoryStream or a FileStream.
2. remove the XML declaration => <?xml version ....>
Use my XmlFragmentWriter available at [0]
3. remove the white space / tab of the xml structure


Set the Formatting property of your XmlTextWriter to Formatting.None. This
should be the default though ...

[0]

http://www.gotdotnet.com/Community/U...b-3a0a9e13bbe3

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Cobban | last post by:
I must be missing something. I am using org.apache.xml.serialize.XMLSerializer to save a DOM but I am not getting non-basic characters converted to UTF-8. I create Text nodes in the DOM by,...
3
by: Integer Software | last post by:
Hi. I have a really simple set of classes that writes 2 pathnames to a xml file. I can write the default ok. Then if I change 1 pathname to a shorter one, then rewrite the xml file, the remains...
5
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not...
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...
4
by: Sebastien Tardif | last post by:
Subject: XmlSerializer.Deserialize complain when root declare the namespace If I do XmlSerializer.Deserialize( myString ) and myString is: String myString = "<?xml version=\"1.0\"...
3
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as...
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
5
by: Phil Galey | last post by:
I'm using XMLSerializer to serialize hierarchical Class-based objects and their content to XML. There are a number of fields (i.e. properties) that are optional, meaning that if no data id written...
0
by: theonlydavewilliams | last post by:
Hi there I'm hoping there's an easy answer to a (hopefully) not too long-winded issue... I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.