Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Append to a file using XML Serialization? Easy way to do this? >Thread Next - Re: Append to a file using XML Serialization? Easy way to do this? Re: Append to a file using XML Serialization? Easy way to do this?To: NULL Date: 7/20/2009 7:56:00 AM On Jul 20, 5:39=A0am, Martin Honnen <mahotr...@yahoo.de> wrote: > > The .NET framework allows you to create an XML fragment by setting > =A0 =A0settings.ConformanceLevel =3D ConformanceLevel.Fragment; > on your XmlWriterSettings variable. That way you should be able to write > out serveral DecoratedPerson elements. You should however be aware that > you can't read the generated XML with XmlDocument or XDocument as these > implement the W3C specification for well-formed XML documents to have > exactly one root element that contains all other elements. > XmlReader on the other hand can also be set in "fragment mode" with an > XmlReaderSettings instance and the same ConformanceLevel setting. > I thank you for your time. I am able to generate fragments, but like you say they miss the "exactly one root element". Can you post, in pseudo-code or words, how to generate a root element programically once you have nodes (fragments)? Let's say you have these node fragments: <Person> <FirstName> joe </FirstName> <LastName> smith </LastName> </Person> <Person> <FirstName> Sam </FirstName> <LastName> Miller </LastName> </Person> In one file, now how can you add a root element in an easy way? Such as <?xml version=3D"1.0" ?> <MyRootElementHere> // above 2 nodes go here </MyRootElementHere> I can do this the "hard way" by mechanically inserting text into another text file, but I'm wondering if there's a quick way to convert fragments into well formed XML documents (there should be--this must be a reoccuring common problem). Unless there is an easy way to do this, I am going back to using DOM and "TextWriter", etc, node by node, which at least I am able to form well formed XML documents (but it's tedious to do). RL | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
