473,703 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing the Xml Declaration Using XmlDocument

Dan
Is there a better way to include the XML declaration than the following?

XmlDeclaration dec
=m_XMLDocument. CreateXmlDeclar ation("1.0",str ing.Empty, "yes");
m_XMLDocument.I nsertBefore((Xm lNode)dec,
(XmlNode)m_XMLD ocument.Documen tElement);
XmlTextWriter writer = new
XmlTextWriter(m _FileName,Encod ing.Default);
writer.WriteRaw (m_XMLDocument. OuterXml);
writer.Flush();
writer.Close();
Nov 12 '05 #1
3 9049
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*@dont spamme.com]
Posted At: Tuesday, September 21, 2004 6:36 AM
Posted To: microsoft.publi c.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. CreateXmlDeclar ation("1.0",str ing.Empty, "yes");
m_XMLDocument.I nsertBefore((Xm lNode)dec,
(XmlNode)m_XMLD ocument.Documen tElement);
XmlTextWriter writer = new
XmlTextWriter(m _FileName,Encod ing.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.Wri teTo, passing the TextWriter as an argument. Or does it just not make a difference?

"Christoph Schittko [MVP]" <IN**********@a ustin.rr.com> wrote in message news:OE******** ******@TK2MSFTN GP15.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*@dont spamme.com]
Posted At: Tuesday, September 21, 2004 6:36 AM
Posted To: microsoft.publi c.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. CreateXmlDeclar ation("1.0",str ing.Empty, "yes");
m_XMLDocument.I nsertBefore((Xm lNode)dec,
(XmlNode)m_XMLD ocument.Documen tElement);
XmlTextWriter writer = new
XmlTextWriter(m _FileName,Encod ing.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,Encod ing.Default);

writer.WriteSta rtDocument();

m_XMLDocument.W riteTo( writer );

Christoph



_____

From: Dan [mailto:da*@dont spamme.com]
Posted At: Tuesday, September 21, 2004 8:38 AM
Posted To: microsoft.publi c.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.Wri teTo, passing the TextWriter as an argument. Or does it
just not make a difference?

"Christoph Schittko [MVP]" <IN**********@a ustin.rr.com> wrote in message
news:OE******** ******@TK2MSFTN GP15.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*@dont spamme.com]
Posted At: Tuesday, September 21, 2004 6:36 AM
Posted To: microsoft.publi c.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. CreateXmlDeclar ation("1.0",str ing.Empty, "yes");
m_XMLDocument.I nsertBefore((Xm lNode)dec,
(XmlNode)m_XMLD ocument.Documen tElement);
XmlTextWriter writer = new
XmlTextWriter(m _FileName,Encod ing.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
2028
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
3719
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> </configuration>
2
11403
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 remove it 1) XSLT templates? 2) Copy all the contents into a new node and leave out the namespace? Use this node node in lieu of the old one?
1
2921
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
3344
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? XmlTextWriter writer = new XmlTextWriter(m_FileName, Encoding.Default); writer.WriteStartDocument(true); m_XMLDocument.WriteTo(writer); writer.Flush(); writer.Close();
0
931
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, (if it exists), or create a new XML file with the item in it if the file doesn't exist. Bearing in mind I'm on the compact framework, does anyone have any suggestions how i can check the file ?
5
2529
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(); doc.WriteTo(xw);
1
1983
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" xsi:schemaLocation="http://abcd.com message.xsd"> Can you please let me know what needs to be done. I need the solution urgently, any help will be greatly appreciated.
0
8747
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9240
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8998
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8955
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6585
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3113
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 we have to send another system
2
2430
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.