Serialize to existing file and remove declaration

younoname

New Member
I have two classes which need to be in same xml file. The way the classes are done mean I'm having to serialize separately. Which I have managed to do. The first I do using TextWriter.\[code\]TextWriter writer = new StreamWriter(filepath);serializer.Serialize(writer, class, ns);\[/code\]This works fine. Then I wanted to add another class to the file. So did same but added that I want to append not overwrite.\[code\]TextWriter writer = new StreamWriter(filepath, true);\[/code\]This adds the new class to end but also adds another declaration so my XML file reads.\[code\]<?xml version="1.0" encoding"utf-8"?><dog>...</dog><?xml version="1.0" encoding"utf-8"?><cat>...</cat>\[/code\]I've tried to use XmlWriter so I could use XmlWriterSettings then chose false for OmitXmlDeclaration but then it overrides the previous class I serialized.
 
Back
Top