| re: How to create an XML document with XmlTextWriter?
Have you tried calling Flush or closing the writer after finishing writing
the data ?
I.e. after
writer.WriteEndDocument();
add this line:
writer.Close(); // alternatively, you can call writer.Flush()
--
Daniel D.C. [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights
"Dave" <anonymous@discussions.microsoft.com> wrote in message
news:43CE3CBA-70F6-4A63-81CB-33941C67CB86@microsoft.com...[color=blue]
> Hi, I'm trying to create an XML document with XMLTextWriter but I want to[/color]
store it in memory (not write it to a file like so many examples do). I
tried the following but with no luck. Should I not user this object for
this purpose? Thanks, Dave.[color=blue]
>
> MemoryStream stm = new MemoryStream();
> XmlTextWriter writer = new XmlTextWriter(stm, System.Text.Encoding.UTF8);
> writer.WriteStartDocument();
> writer.WriteComment("This Is A List of My Books");
> writer.WriteStartElement("MyBooks");
> writer.WriteStartElement("Book");
> writer.WriteAttributeString("ISBN", "1861005652");
> writer.WriteAttributeString("Title", "Professional Visual Basic[/color]
Interoperability");[color=blue]
> writer.WriteElementString("Author", "Billy Hollis");
> writer.WriteElementString("Author", "Rockford Lhotka");
> writer.WriteEndElement();
> writer.WriteEndElement() ;
> writer.WriteEndDocument();
>
> XmlTextReader xr = new XmlTextReader(stm);
> XmlDocument xmldoc = new XmlDocument();
> xmldoc.Load(xr);
>
> But get....
>
> The root element is missing[/color] |