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 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();
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
