473,373 Members | 1,179 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,373 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 9020
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fede | last post by:
Hi to all! How can I replace a DocumentType Declaration in a XML file using XMLDocument and XPath? Thanks in advance. Fede.
3
by: Raj Kumar | last post by:
Hi! I have a text file that looks like this: <configuration> <appSettings> <add key="db_server" value="someserver" /> <add key="db_database" value="somedatabase" /> </appSettings>...
2
by: Manoj G | last post by:
Hello, I believe there is no way to remove the default namespace declaration (For eg <DataSet xmlns="something">.... ) on an XmlNode object directly through DOM. So, what is the best way to...
1
by: Dan | last post by:
How would I write an XmlDocument to a file so that each node is properly indented and followed by a carriage return? Thanks...Dan
1
by: Dan | last post by:
I'm trying to write an XmlDocument to disk using an XmlTextWriter. Everything is fine except that I can't get the XML declaration to come out. I'm using the code below. What am I doing wrong? ...
0
by: Eric W | last post by:
Hi, I'm working on the .NET Compact Framework, and I need a way in which i store products in an xml file. Basically, when i add a product to the system, i want to either add it to the XML file,...
5
by: Andy Fish | last post by:
Hi, I am using XmlDocument.WriteTo() and I find that the xml declaration is not included. at the moment I am doing this: XmlTextWriter xw = new XmlTextWriter(...); xw.WriteStartDocument();...
1
by: anoop.mangal | last post by:
I need to form an xmlelement like the declaration below: <message xmlns="http://abcd.com" xmlns:s2s="http://abcd.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.