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!


0
Vlad1 (3)
3/21/2005 10:48:09 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
1573 Views

Similar Articles

[PageSpeed] 17

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.)

0
v-schang (36)
3/22/2005 8:07:45 AM
Thanks a lot Steven!  I'll try it.
"Steven Cheng[MSFT]" <v-schang@online.microsoft.com> wrote in message
news:Oi4qDZrLFHA.708@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.)
>


0
Vlad1 (3)
3/22/2005 11:52:24 AM
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.)

0
v-schang (36)
3/23/2005 1:08:37 AM
Reply:

Similar Artilces:

DataSet to XML
I have data coming from SQL Server and need to write out some XML. I have a schema(xsd) for this XML file. Right now I am bringing in the DataSet and writing out the elements and attributes myself using xmltextwriter to match schema without really using the xsd at the time of writing. The file I create validates but I was wondering is there a better way? I see things like inferschema method off of dataset, can this be used? How do you map columns in a dataset with elements and attributes in the schema? I know dataset.WriteXmL will write XML but that match my schema. Appreciate any help! Tha...

Can't load xml containing \v
I have an xml document that I am trying to load, which contains RTF text. I get the error, "{"'\v', hexadecimal value 0x0B, is an invalid character. Line 1, position 24." }" when I call this code. System.Xml.XmlDocument xmlNewDocument = new System.Xml.XmlDocument(); xmlNewDocument.LoadXml("<TextExpanderPlainText>\v</TextExpanderPlainText>"); This loads without any errors in IE, but not .Net XML. Is there anything I can do to get the xml string to load not knowing if it may contain any special processing values like "\v"? Than...

Compare two XML Files and save to One
Hi all, I feel like this question has been asked before but I just cannot seem to find a good answer. Q: Is there a way to have two XML files and compare them and save them to one. Example: XML-A: <Season> <Fruit>Orange</Fruit> <Fruit>Strawberry</Fruit> </Season> XML-B: <Season> <Fruit>Orange</Fruit> <Fruit>Banana</Fruit> </Season> Output to XML-C would be: <Season> <Fruit>Orange</Fruit> <Fruit>Strawberry</Fruit> <Fruit>Banana</Fruit> </Season> I downloaded and ins...

1 serial port 2 parity types? MFC based app needs assistance.
Hello all I am workiing in MFC on an app which has an odd requirement.. for me anyway. I have only one serial port availbale. The task is that one portion of my GUI has to send serial data out with EVEN parity. The other, a keypad, has to send serial data out with ODD parity. The reciever is always receiving ODD parity. So.. unless I am wrong.. I am thinking I have to switch to ODD parity before sending out keypad strings and tehn, when the last character is shifted out I hvae to set the port back to even parity in time to get the host's response. Anyone have any ideas? How do ...

Replace INI with XML
Looking for sample VB6 code to replace the functionality of INI related code with code to do the same using XML. Googling did not help me. WriteXMLString sSec,sKey, sItem sItem=ReadXMLString(sSec,sKey) DeleteXMLString(sSec,sKey) vArray=ReadXMLSection(sSec) DeleteXMLSection(sSec) etc. "Bee" <Bee@discussions.microsoft.com> wrote in message news:495D3696-628D-4266-A0A0-750E483A27D7@microsoft.com... > Looking for sample VB6 code to replace the functionality of INI related code > with code to do the same using XML. Googling did not help me. > WriteXMLS...

How to link xml with xsd "externally"?
Right now, in order to validate my xml file against xsd, I include the following line in the xml file: xmlns="urn:mySchemaName". Is it possible to link xml to xsd without specifying the schema inside the xml file? Thank you! Eve wrote: > Right now, in order to validate my xml file against xsd, I include the > following line in the xml file: xmlns="urn:mySchemaName". xmlns="urn:mySchemaName" is a namespace declaration, not an "instruction" to validate against a schema. You should use xsi:schemaLocation and/or xsi:noNamespaceSchemaLocation att...

XML Pipeline
Hi. We were apprached by our supplier to update our inventory using their xml output. The question I have is how (brief overview) would this work and what are the security concerns. Our system was design in .net with a sql 2000 back-end. I understand that this is a fairly basic question for this group, but I'd thought that I'd ask here and recieve expert insight. Thank you in advance for your assistance. JJ ...

XML Export Weirdness?
Hi, I'm trying to use Excel 2003 to create some XML. I'm almost there, however I'm encountering some weirdness. Specifically, in the XML I use to create my map I've got some tags that looks like this: <?xml version="1.0" encoding="UTF-8"?> <enterprise> <extension> <WEBCREDENTIAL xmlns="http://www.webct.com/IMS">abc123</WEBCREDENTIAL> </extension> </enterprise> However, when I export it from excel as XML it looks like this: <?xml version="1.0" encoding="UTF-8" standalone="ye...

XML Root Node
I have a file I'm using as a Configuration file (configuration as in options and such). When I create the xml file in the .Net IDE, it places the following (snip): <Configuration xmlns="Blah"> </Configuration> This is the way I'd like it but it doesn't work this way :( When I validate it against the xsd file, it says that it's invalid. (Can't remember error, don't have time to reproduce). The fix is changing it to the following: <cfg:Configuration xmlns:cfg="Blah"> </cfg:Configuration> So, just need 1 of the two (...

Pretty print XML?
I am sure this has been asked enough to warrant an FAQ but I could not find it. Does anyone have some code and maybe an XSLT stylesheet that would allow me to transform an XML string to a "pretty" version (nodes indented on separate lines, etc.)? Thank you for your help. Kevin Kevin Burton wrote: > I am sure this has been asked enough to warrant an FAQ but I could not > find it. > > Does anyone have some code and maybe an XSLT stylesheet that would allow > me to transform an XML string to a "pretty" version (nodes indented on > separate lines, et...

Creating an XML document
Hi, First of all, a confession. This is a cross post from the microsoft.public.dotnet.general list. I posted there not realising that this list existed. Apologies to those who read both lists. I'll do my best to prevent two separate conversations developing. I'm trying to create an XML Document. This is what I want to end up with: <?xml version="1.0" encoding="UTF-8" ?> <epp xmlns="urn:iana:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0...

Reading in an XML Web-based page
I would like to be able to import the following xml document on a daily basis to get the current exchange rates and then create the same output file so I can use Biztalk 2002 to import that file, but I am not sure how to do it? Any ideas would be greatly appreciated. http://www.bankofcanada.ca/stat/fx-xml.xml This will make a local copy of the XML data: using System; using System.Xml; class Program { static void Main(string[] args) { XmlDocument doc = new XmlDocument(); doc.Load("http://www.bankofcanada.ca/stat/fx-xml.xml"); doc.Save("c:\\temp\\...

Serializing Null Strings
Hi, I'm using XmlSerializer to serialize a class which contains a String among other things (ints, chars etc.. simple stuff). The string is returned from a database and as such may be null. Now the XmlSerializer will serialize the class as long as the String is not null. I've tried applying the [System::Xml::Serialization::XmlElementAttribute(IsNullable = false)] attribute to the data member but this has not changed the situation. Has anyone else had this problem before? And know how to fix it or work around it? It must be possible to serialize null strings! Cheers John ...

getting started in XML & XSLT
I've never had the need to work with XML, but I believe I now have an appropriate application. I have time-series data in objects organized as a tree that I want an ASP.NET program to write out to web pages formatted as a matrix. It is not a simple matrix, since the number of row heading cells can vary, but the data cells must be aligned by date (so the heading cells will not be uniformly sized). example of typical rows: 3 heading cells, 4 data cells (by year) 2 heading cells, 4 data cells (by year) etc. I think what I should do is convert the tree structure to XML and use XSLT (and/or X...

prerequisites for xml
Hello! I'd like to know what are the reequisites to program in xml As long as you understand tagged languages, like HTML, you should be able to get a good grasp of XML. -- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA ************************************************ Think Outside the Box! ************************************************ "oyster" <anonymous@discussions.microsoft.com> wrote in message news:8900C2BF-5198-4DEA-8577-2AC4922E7BB0@microsoft.com... > Hello! I'd like to know what are the reequisites to program in xml ...

How can I compare 2 XML dataset schemas?
Hi, How can I comapre 2 dataset schemas are compatible (Same table columns, same keys, same constraints, ...)? "Leon_Amirreza" <r_rahmaty@hotmail.com> wrote in message news:e90a55x3HHA.5984@TK2MSFTNGP04.phx.gbl... > Hi, > How can I comapre 2 dataset schemas are compatible (Same table columns, > same keys, same constraints, ...)? You can use the System.Xml.Schema.XmlSchema class. You can load the schemas from .XSD files using the Read method. You will then have to recursively compare the two object graphs. -- John Saunders [MVP] ...

Serial Programming in VC++ 6
Can someone help me with some code to communicate in single bytes to and from comm ports using Visual C++ 6.0 This article might help: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp Bob "Eddard" <Eddard@eddard.com> wrote in message news:46uOe.11670$3%1.4589@trndny08... > Can someone help me with some code to communicate in single bytes to and > from comm ports using Visual C++ 6.0 > > I have not done this but take a look at the following class library: http://www.naughter.com/serialport.html It has some sample...

Re: Re: api to check wheter xml is well formed #2
You mean the XmlTextReader. Ashish wrote: > Are there any functions in .Net which can be used to verify whether xml is > well formed? That's quite unusual requirement. Usually, when XML is built using XML API such as XmlTextWriter you don't need to check if it's well-formed - you can trust standard API. When your XML is loaded into in-memory store, such as XmlDocument - it's well-formed by definition. And when you just have a string or file and want to check it's well-formdness, use XmlTestReader: XmlReader r = new XmlTextReader(...); try { while (r.Read()...

XML Parsing Peformance
Hi, I have a xml file that is similar to a config file however this xml file is for an assembly. Currently, I parse the xml file using XMLReader however my assembly parses this file alot so I was wondering if I should use a different approach like loading it in memory in XMLDocument. However, this assembly is used in a web app that handles many users so there could be many instances of objects from the assembly. Is loading it into a XMLReader many times hurt performance badly? Thanks * george wrote in microsoft.public.dotnet.xml: >I have a xml file that is similar to a config...

Random access of XML file
I have the XML file which has a structure similar to one I pasted at the end of this post. As you can see many elements are using different id attributes. For example element Window uses WinID attribute as ID, the ViewData uses ViewID attribute as an ID and so on. I need to read this file without assuming what is the order of the elements, in other words I can't read it sequentially. The reason for this requirement is that whole WindowsInfo element might be missing for example or Object Info might be first and WindowsInfo second etc. Since many elements have the same name and diffe...

Validating XML w/o Namespace against XSD
I am trying to validate an XML file that does not contain any xmlns: namespace attribute against a predefined XSD schema. I should think this would be easy to do, since there must be far more "unqualified" XML files out there than there are ones that include a namespace reference. Unfortunately, as I am coming to hate about all things XML, the easy things are extraordinarily difficult and/or subtle. I know how to create a schema collection dynamically and validate qualified XML files against it. But I can't figure out the "no namespace in the XML file" situation (oth...

Enum serialization
I take an error trying serialize a member in document class of type enum... binary '>>' : no operator found which takes a right-hand operand of type 'Elementi' (or there is no acceptable conversion) where i defined enum Elementi{Line,Rectangles,Circle,Curve,TEXT}; enum Elementi m_element; and for example m_element = Line; so in serialize doc function i have in my serialize function... if (ar.IsStoring()) { ar << m_color // Store the current color << m_element // the current element type, !!!THIS LINE GIVES NO ERROR!!! << m_PenWidth // and the cu...

deserialize CDATA section in XML
Hi, I have got xml document with CDATA sections containing special characters like links to images. All Iwant is to display the content withing my div section. Can you provide me a snippet of a code. Thank you in advance. Darek T. Dariusz Tomo� wrote: > I have got xml document with CDATA sections containing special characters > like links to images. All Iwant is to display the content withing my div > section. Can you provide me a snippet of a code. Can you show us an example of the CDATA section and show us what kind of HTML you want to generate? Then we can certainly hel...

XML - Xpath
Hello everyone, I contact this discussiongroup because I encountered a little problem with XSL. Let me explain it: I have following file "position.xml": <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="position.xsl"?> <data> <curve> <point>alfa</point> <point>beta</point> </curve> <curve> <point>gamma</point> <point>delta</point> </curve> </data> I have following file "position.xsl": <?xml ve...

Cannot display XML in Outlook 2003
Hi! I have a user whose Outlook 2003 profile does not allow her to display XML code when embedded in an email. The XML was generated by another user using Microsoft Publisher 2003. Below are my findings so far: - User is using Outlook as her editor. This should not have an effect on reading email, but I wanted to throw that in just in case. - She can read other emails okay (HTML, richtext, etc.) - When she moves over to another PC, she can read XML. - When others jump on her PC and log in as different users, they can read the XML just fine. The PC is Windows XP Pro SP2 with the latest sec...