473,503 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14693
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
367
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
4871
by: raj | last post by:
Can any one let me know how I can DOCTYPE (DTD declaration) to the XML generated by XmlSerializer
3
3155
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
2441
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
1735
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
11379
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
6104
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
11044
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
5533
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
7205
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
7093
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...
1
7006
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
7467
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...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.