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
"Amy L." <am**@paxemail.com> wrote in message
news:c7**************************@posting.google.c om...
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
class in my application. When I serialize my class it produces the
following line.
<?xml version="1.0" encoding="utf-16"?>
for each instance of my serialized class. Thus giving me the
following output.
<?xml version="1.0" encoding="utf-16"?>
<Message>
...
</Message>
<?xml version="1.0" encoding="utf-16"?>
<Message>
...
</Message>
I just want the following
<Message>
...
</Message>
<Message>
...
</Message>
as I will be adding some of my own formatting to the xml file when I
write it out to a file. So my questions are
[1] Can I remove the <?xml version="1.0" encoding="utf-16"?> line?
[2] If I can't remove it does it really matter that its in thier?
Amy.