473,320 Members | 1,977 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,320 software developers and data experts.

Writing the Xml Declaration Using XmlTextWriter

Dan
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();
Nov 16 '05 #1
1 3324
Dan
Here is what I ended up doing. Is this the best way to do this?

XmlDeclaration dec =
m_XMLDocument.CreateXmlDeclaration("1.0",string.Em pty, "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();

"Dan" <da*@dontspamme.com> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
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();

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan | last post by:
Is there a better way to include the XML declaration than the following? XmlDeclaration dec =m_XMLDocument.CreateXmlDeclaration("1.0",string.Empty, "yes");...
0
by: Marc Schumacher via DotNetMonster.com | last post by:
Hi, I am writing a client/server application with a desktop and a pocketPC which transfers a xml string which is to be loaded by a dataset on the client. the server uses this code 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
13
by: jcrouse | last post by:
Here is some of my code Dim myXmlTextWriter As XmlTextWriter = New XmlTextWriter("C:\CPViewer\CPViewer.xml", System.Text.Encoding.Unicode myXmlTextWriter.Formatting =...
2
by: Mori | last post by:
I am using the following code to manufactue xml using xmltextwriter. The xml is okay except for the extra set of start document and the outer <string> element. Where do they come from and how do...
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();...
4
by: Paul Hadfield | last post by:
Hi, Wonder if anyone can help me on this, In DotNet2.0 I've been quite happily using the WriteAttributeString method of XmlWriter object, but have run into a problem when trying to output a...
2
by: darrel | last post by:
I was having issues before with my XML being sent to the browser as UTF16. Via my XmlTextWriter, was able to fix this by explicitely setting the encoding to UTF8: Dim objX As New...
16
by: billsahiker | last post by:
I am researching for an upcoming c# .net 2.0 project that may require reading and writing xml files. I don't want to use xmltextreader/ xmltextwriter as I prefer to have lower level file access...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.