xmltextwriter

G

Guest

when I try to write to an xml doc. it only creates it and never writes to it
heres my code:

private XmlTextWriter xtw;
private void btnSave_Click(object sender, System.EventArgs e)
{
xtw = new XmlTextWriter(@"C:\Videos.xml", null);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 3;
// Start the XML document.
xtw.WriteStartDocument();

xtw.WriteComment("Video Library");
xtw.WriteComment(
"This is a file containing a number of videos.");

// Add elements to the file
xtw.WriteStartElement("p", "person", "urn:person");
xtw.WriteStartElement("LastName","");
xtw.WriteString("Chand");
xtw.WriteEndElement();
xtw.WriteStartElement("FirstName","");
xtw.WriteString("Mahesh");
xtw.WriteEndElement();
}
}
}
It creates the file but never writes to it and when I try to open itin ie it gives me an error.
 
E

Emil Kvarnhammar

Hi Freddy.

Look at the .NET Framework SDK documentation for XmlTextWriter!!!
If you add the following it will work:

writer.WriteEndDocument();
//Write the XML to file and close the writer.
writer.Flush();
writer.Close();


/Emil Kvarnhammar


freddy said:
when I try to write to an xml doc. it only creates it and never writes to it
heres my code:

private XmlTextWriter xtw;
private void btnSave_Click(object sender, System.EventArgs e)
{
xtw = new XmlTextWriter(@"C:\Videos.xml", null);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 3;
// Start the XML document.
xtw.WriteStartDocument();

xtw.WriteComment("Video Library");
xtw.WriteComment(
"This is a file containing a number of videos.");

// Add elements to the file
xtw.WriteStartElement("p", "person", "urn:person");
xtw.WriteStartElement("LastName","");
xtw.WriteString("Chand");
xtw.WriteEndElement();
xtw.WriteStartElement("FirstName","");
xtw.WriteString("Mahesh");
xtw.WriteEndElement();
}
}
}
It creates the file but never writes to it and when I try to open itin ie
it gives me an error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top