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

XmlDocument not being written to

Hi Everyone,

I am using the following code to write out an XmlDocument that I have.
I create an XmlTextWriter and try to save / flush it. Earlier, I had
created an XmlElement (using xmlDoc.createElemenet("name') )

However, the xml file size is always 0. WHat could I be missing?

private void writeXMLFile()
{
XmlTextWriter x = new XmlTextWriter(XmlFileName, null);
xmlDoc.Save(x);
x.Flush();
x.Close();

return;
}

Thanks.

May 1 '07 #1
2 2152
On May 1, 3:54 pm, C Sharp <a.kamr...@gmail.comwrote:
Hi Everyone,

I am using the following code to write out an XmlDocument that I have.
I create an XmlTextWriter and try to save / flush it. Earlier, I had
created an XmlElement (using xmlDoc.createElemenet("name') )
One thing that I noticed while debugging this is that when I view the
xmlDoc's Inner XML (in debugger) [via XML Visualizer] it says, "xml
document must have top level element". Does this mean that my xmlDoc
was not instantiated correctly? I had used the default constructor to
create my xmlDoc.

Thanks.
May 1 '07 #2
"C Sharp" <a.*******@gmail.comwrote in message
news:11*********************@n59g2000hsh.googlegro ups.com...
Hi Everyone,

I am using the following code to write out an XmlDocument that I have.
I create an XmlTextWriter and try to save / flush it. Earlier, I had
created an XmlElement (using xmlDoc.createElemenet("name') )

However, the xml file size is always 0. WHat could I be missing?

private void writeXMLFile()
{
XmlTextWriter x = new XmlTextWriter(XmlFileName, null);
xmlDoc.Save(x);
x.Flush();
x.Close();

return;
}
You didn't append the created element to the document. The Create* calls
create their corresponding nodes, but don't put them anywhere.
--
John Saunders [MVP]
May 1 '07 #3

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

Similar topics

0
by: James Thurley | last post by:
I'm creating an XmlDocument manually, adding content using the Xml classes such as XmlElement and XmlText, and I then write it out as as "text/xml" to the HttpResponse.Output TextWriter object...
5
by: John Bailo | last post by:
I wrote a webservice to output a report file. The fields of the report are formatted based on information in an in-memory XmlDocument. As each row of a SqlDataReader are looped through, a...
6
by: Yechezkal Gutfreund | last post by:
I have been using the following code (successfully) to read Xml formated text packets from a TCP stream. The output from the server stream consists of a sequence of well formed Xml documents...
4
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the...
4
by: barney | last post by:
Hello, I' m using .NET System.Xml.XmlDOcument. When I do the following: XmlDocument xml = new XmlDocument(); xml.Load("blah"); .... xml.Save("blub"); I've got the problem that the following...
4
by: Mogens Nielsen - Elbek & Vejrup A/S | last post by:
Hi all, I have an application loading xml-documents. The purpose is just to load the document and do some processing. The documents is generated by external vendors outside my company. Some of...
4
by: David Thielen | last post by:
Hi; I have nodes in the XmlDocument I create that need to be written exactly as is - not converting < to %lt; and no changing the whitespace. (This is for the SpreadsheetML schema and it reads...
0
by: BC3Tech | last post by:
I'm creating a system that uses XML to store an audit trail of the steps that it has been through in the system. The way the schema is defined, there is a "Tag" for every application that...
4
by: saish | last post by:
Hello Need your help, I have a C++ win32 dll which takes xml document type by reference. I need to call this dll from c# .net. I tried using DllImport, but dll funtion when call does not...
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();...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.