Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Append to a file using XML Serialization? Easy way to do this?

From: RayLopez99 <raylopez88@-----.--->
To: NULL
Date: 7/20/2009 9:58:00 AM
On Jul 20, 11:20=A0am, Martin Honnen <mahotr...@yahoo.de> wrote:
> RayLopez99 wrote:
> > Can you post, in pseudo-code or words, how to generate a root element
> > programically once you have nodes (fragments)?
>
> Why "once you have nodes"? Why can't you simply write out the root
> element with your XmlWriter with writer.WriteStartElement("root") and
> then pass on that writer to your XmlSerializer?

Martin Honnen - thank you!  I fixed it, using your suggestion above.
For my problem it was trivial--see the post below at //IMPORTANT-MUST
ADD!  Adding these two lines for the Root Element (.WriteStartElement)
allowed me to add as many nodes as I want from my List.

Thanks again.  The rest of your post I did not understand but for my
purposes I'm finished with this problem.

RL

// program same as original post except for the below...

            string totalFilepath =3D Path.Combine
(Request.PhysicalApplicationPath, @"App_Data
\XMLPasswordDoc77.xml");  //create path
            XmlSerializerNamespaces ns =3D new XmlSerializerNamespaces
();
            //ns.Add("", "");
            ns.Add("mytest", "http://www.w3.org/2001/XMLSchemaMyOwn");

             XmlWriterSettings settings =3D new XmlWriterSettings();
             settings.OmitXmlDeclaration =3D false; // do not Remove the
<?xml version=3D"1.0" encoding=3D"utf-8"?>

             XmlWriter writer =3D XmlWriter.Create(totalFilepath,
settings);
             writer.WriteStartElement("ARootElement"); //IMPORTANT-
MUST ADD!


            XmlSerializer serializer =3D new XmlSerializer(typeof
(DecoratedPerson));
            foreach (DecoratedPerson p in myDecPersonList)
            {

                 serializer.Serialize(writer, p, ns); //now you can,
using Martin's suggestion, write as many nodes from the List
myDecPersonList as you want--not limited to one node.
            }

            writer.WriteEndElement();//IMPORTANT-MUST ADD!


            writer.Close();


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent