473,386 Members | 1,694 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,386 software developers and data experts.

DOCTYPE with Xml Serialization

I have a class that serialize using the XmlSerializer.
I am using several attributes for class members to control serialization
process.
One thing I cannot figure out how to do is how to add DOCTYPE attribute to
the file.
This XML file must use the doctype that refers to the DTD rather than an
XSD.

Could someone point out how to accomplish that using the attributes or by
some other means?

Thanks!
Nov 12 '05 #1
3 14667
Hi Vlad,

Welcome to MSDN newsgroup.
From your description, when you use the .NET XmlSerizliation to serizliaze
some class instances out to xml stream, you want to also expose the DocType
for the whole xml document, yes?

As for the DOCTYPE, there hasn't buildin XmlSerlization Attributes for
specifying DOCTYPE. In fact, this is because the Xml Serialization is
Class/Element based rather than Document based. As for DOCTYPE, it is
specified for a certain Xml document. Currently I think we can use the
following means to inject the DOCTYPE in our serilization's output document:

When do the serizliation, we use an XmlTextWriter to delegate the
underlying StreamWriter we'll write out the serialized instances. And we
can use the XmlWriter.WriteDocType to inject our custom DocType. For
example:

XmlSerializer serializer = new XmlSerializer(typeof(Group));

Group group = new Group();
StreamWriter sw = new StreamWriter("group.xml");
XmlWriter xw = new XmlTextWriter(sw);

xw.WriteDocType("Group", null, null, "<!ENTITY h 'hardcover'>");

serializer.Serialize(xw,group);

xw.Close();
sw.Close();

HTH. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 12 '05 #2
Thanks a lot Steven! I'll try it.
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Oi*************@TK2MSFTNGXA02.phx.gbl...
Hi Vlad,

Welcome to MSDN newsgroup.
From your description, when you use the .NET XmlSerizliation to serizliaze
some class instances out to xml stream, you want to also expose the DocType for the whole xml document, yes?

As for the DOCTYPE, there hasn't buildin XmlSerlization Attributes for
specifying DOCTYPE. In fact, this is because the Xml Serialization is
Class/Element based rather than Document based. As for DOCTYPE, it is
specified for a certain Xml document. Currently I think we can use the
following means to inject the DOCTYPE in our serilization's output document:
When do the serizliation, we use an XmlTextWriter to delegate the
underlying StreamWriter we'll write out the serialized instances. And we
can use the XmlWriter.WriteDocType to inject our custom DocType. For
example:

XmlSerializer serializer = new XmlSerializer(typeof(Group));

Group group = new Group();
StreamWriter sw = new StreamWriter("group.xml");
XmlWriter xw = new XmlTextWriter(sw);

xw.WriteDocType("Group", null, null, "<!ENTITY h 'hardcover'>");

serializer.Serialize(xw,group);

xw.Close();
sw.Close();

HTH. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 12 '05 #3
You're welcome Vlad,

Good Luck!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 12 '05 #4

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

Similar topics

1
by: Vlad | last post by:
I have a class that serialize using the XmlSerializer. I am using several attributes for class members to control serialization process. One thing I cannot figure out how to do is how to add...
3
by: raj | last post by:
Can any one let me know how I can DOCTYPE (DTD declaration) to the XML generated by XmlSerializer
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
20
by: Deborah | last post by:
I'm trying to clean up my website, and it's in pretty good shape now, but I've gotten confused reading about Doctypes. My site is http://www.simi-therapy.com and my CSS is...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
5
by: Nikola Skoric | last post by:
I ran in Mono a program developed on .NET Framework 2.0 and it ran OK until I tried to desirialize a object. There the program died abruptly dumping this: System.ArgumentOutOfRangeException:...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.