472,145 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Writing the Xml Declaration Using XmlDocument

Dan
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();
Nov 12 '05 #1
3 8945
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
-----Original Message-----
From: Dan [mailto:da*@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();

Nov 12 '05 #2
Dan
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]" <IN**********@austin.rr.com> wrote in message news:OE**************@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
-----Original Message-----
From: Dan [mailto:da*@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();


Nov 12 '05 #3
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:da*@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]" <IN**********@austin.rr.com> wrote in message
news:OE**************@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
-----Original Message-----
From: Dan [mailto:da*@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();

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Raj Kumar | last post: by
2 posts views Thread by Manoj G | last post: by
1 post views Thread by Dan | last post: by
reply views Thread by Eric W | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.