> [2] If I can't remove it does it really matter that its in thier?
Well, basically you can avoid it, but why?

Signature
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Amy L. - 07 Sep 2004 20:00 GMT
> > [2] If I can't remove it does it really matter that its in thier?
>
> Well, basically you can avoid it, but why?
Because I am serializing a collection of objects I just want the
object represented in XML without any of the other stuff like "<?xml
version="1.0" encoding="utf-16"?>".
ie.
<Message>
...
</Message>
Than when I get ready to write it out to a file I am going to add some
additional XML to it. Example:
<AllMessages>
<Message>
...
</Message>
</AllMessages>
Is this not the right approach. All I want to do is save each object
in my collection out as XML to a text file to read the objects back in
later. Any thoughts?
Amy.
yes, you can remove it. And yes, it matters that it is in there. The
start-of-document should appear only... uh.... at the start of the XML
document.
To remove it, you need to provide your own implementation of a
System.Xml.XmlTextWriter, and override the WriteStartDocument() method, like
so:
public class XmlTextWriterFormattedNoDeclaration :
System.Xml.XmlTextWriter {
public XmlTextWriterFormattedNoDeclaration (System.IO.TextWriter w) :
base(w) { Formatting= System.Xml.Formatting.Indented;}
public override void WriteStartDocument () { }
}
Then, serialize using that XmlTextWriter, for example:
XmlSerializer s= new XmlSerializer(typeof(Message));
s.Serialize(new
XmlTextWriterFormattedNoDeclaration(System.Console.Out), msg);
of course, You can also serialize to a memory stream or whatever. . .
-Dino
> I am using the xml serializer to serialize the objects out of a
> collection into a file. The object that is being serialized is a
[quoted text clipped - 29 lines]
>
> Amy.