Connecting Tech Pros Worldwide Forums | Help | Site Map

Writing the Xml Declaration Using XmlDocument

Dan
Guest
 
Posts: n/a
#1: Nov 12 '05
Is there a better way to include the XML declaration than the following?

XmlDeclaration dec
=m_XMLDocument.CreateXmlDeclaration("1.0",string.E mpty, "yes");
m_XMLDocument.InsertBefore((XmlNode)dec,
(XmlNode)m_XMLDocument.DocumentElement);
XmlTextWriter writer = new
XmlTextWriter(m_FileName,Encoding.Default);
writer.WriteRaw(m_XMLDocument.OuterXml);
writer.Flush();
writer.Close();



Christoph Schittko [MVP]
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Writing the Xml Declaration Using XmlDocument


No, there is no better way to add an Xml document declaration to an
XmlDocument object.

What are you looking for?

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
[color=blue]
> -----Original Message-----
> From: Dan [mailto:dan@dontspamme.com]
> Posted At: Tuesday, September 21, 2004 6:36 AM
> Posted To: microsoft.public.dotnet.xml
> Conversation: Writing the Xml Declaration Using XmlDocument
> Subject: Writing the Xml Declaration Using XmlDocument
>
> Is there a better way to include the XML declaration than the[/color]
following?[color=blue]
>
> XmlDeclaration dec
> =m_XMLDocument.CreateXmlDeclaration("1.0",string.E mpty, "yes");
> m_XMLDocument.InsertBefore((XmlNode)dec,
> (XmlNode)m_XMLDocument.DocumentElement);
> XmlTextWriter writer = new
> XmlTextWriter(m_FileName,Encoding.Default);
> writer.WriteRaw(m_XMLDocument.OuterXml);
> writer.Flush();
> writer.Close();[/color]


Dan
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Writing the Xml Declaration Using XmlDocument


Re: Writing the Xml Declaration Using XmlDocumentI was curious if someone would say that the preferred way is to use XmlDocument.WriteTo, passing the TextWriter as an argument. Or does it just not make a difference?

"Christoph Schittko [MVP]" <INVALIDEMAIL@austin.rr.com> wrote in message news:OEFLKs9nEHA.3460@TK2MSFTNGP15.phx.gbl...
No, there is no better way to add an Xml document declaration to an XmlDocument object.

What are you looking for?

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
[color=blue]
> -----Original Message-----
> From: Dan [mailto:dan@dontspamme.com]
> Posted At: Tuesday, September 21, 2004 6:36 AM
> Posted To: microsoft.public.dotnet.xml
> Conversation: Writing the Xml Declaration Using XmlDocument
> Subject: Writing the Xml Declaration Using XmlDocument
>
> Is there a better way to include the XML declaration than the following?
>
> XmlDeclaration dec
> =m_XMLDocument.CreateXmlDeclaration("1.0",string.E mpty, "yes");
> m_XMLDocument.InsertBefore((XmlNode)dec,
> (XmlNode)m_XMLDocument.DocumentElement);
> XmlTextWriter writer = new
> XmlTextWriter(m_FileName,Encoding.Default);
> writer.WriteRaw(m_XMLDocument.OuterXml);
> writer.Flush();
> writer.Close(); [/color]

Christoph Schittko [MVP]
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Writing the Xml Declaration Using XmlDocument


Dan,



I was primarily answering your question on how to get the document
declaration into an XmlDocument object. If the object is to get it into
the output file, then why not do:



XmlTextWriter writer = new XmlTextWriter(m_FileName,Encoding.Default);

writer.WriteStartDocument();

m_XMLDocument.WriteTo( writer );



Christoph









_____

From: Dan [mailto:dan@dontspamme.com]
Posted At: Tuesday, September 21, 2004 8:38 AM
Posted To: microsoft.public.dotnet.xml
Conversation: Writing the Xml Declaration Using XmlDocument
Subject: Re: Writing the Xml Declaration Using XmlDocument


I was curious if someone would say that the preferred way is to use
XmlDocument.WriteTo, passing the TextWriter as an argument. Or does it
just not make a difference?



"Christoph Schittko [MVP]" <INVALIDEMAIL@austin.rr.com> wrote in message
news:OEFLKs9nEHA.3460@TK2MSFTNGP15.phx.gbl...

No, there is no better way to add an Xml document declaration to an
XmlDocument object.

What are you looking for?

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
[color=blue]
> -----Original Message-----
> From: Dan [mailto:dan@dontspamme.com]
> Posted At: Tuesday, September 21, 2004 6:36 AM
> Posted To: microsoft.public.dotnet.xml
> Conversation: Writing the Xml Declaration Using XmlDocument
> Subject: Writing the Xml Declaration Using XmlDocument
>
> Is there a better way to include the XML declaration than the[/color]
following?[color=blue]
>
> XmlDeclaration dec
> =m_XMLDocument.CreateXmlDeclaration("1.0",string.E mpty, "yes");
> m_XMLDocument.InsertBefore((XmlNode)dec,
> (XmlNode)m_XMLDocument.DocumentElement);
> XmlTextWriter writer = new
> XmlTextWriter(m_FileName,Encoding.Default);
> writer.WriteRaw(m_XMLDocument.OuterXml);
> writer.Flush();
> writer.Close();[/color]


Closed Thread