"Ferrari, Eduardo" wrote:
> Hi Thanks!
>
> Almost worked!
>
> It blew up when tryed to add the new attribute:
>
> // Remove the root DocumentElement from the document
> xml.DocumentElement.ParentNode.RemoveChild(xml.DocumentElement);
>
> // Create a new element for the build configuration
> XmlElement xmlBuild = xml.CreateElement("Build");
> xmlBuild.SetAttribute("type", BuildType);
> xmlBuild.SetAttribute("sync", BuildSync.ToString());
> xmlBuild.SetAttribute("compile", BuildCompile.ToString());
> xmlBuild.SetAttribute("assemble", BuildAssemble.ToString());
>
> // Append element to document
> xml.AppendChild(xmlBuild);
>
> // Creates a new element for the sync configuration
> XmlElement xmlSync = xml.CreateElement("Sync");
>
> // Set the attribute values for the sync configuration
> xmlSync.SetAttribute("version", SyncVersion);
> xmlSync.SetAttribute("branch", SyncBranch);
>
> // Append element to document
> xml.AppendChild(xmlSync); <--- BLOWS UP HERE
>
> Unhandled Exception: System.InvalidOperationException: This document already
> has a DocumentElement node.
> at System.Xml.XmlDocument.IsValidChildType(XmlNodeType type)
> at System.Xml.XmlNode.AppendChild(XmlNode newChild)
>
>
> --
> Eduardo de Morais Ferrari
> Misys'''''''' OPICS Project
> Stefanini IT Solutions
> White Plains, NY
> Phone: (914) 821-2727
> Cell: (914) 406-5027
> eduardo.ferrari@misys.com
>
>
> "Martin Honnen" wrote:
>
> >
> >
> > Ferrari, Eduardo wrote:
> >
> >
> > > private static BuildConfiguration SaveXML(XmlDocument xml, string fileName)
> > > {
> > > // Creates the nodelist
> > > XmlNodeList nodeList;
> > > XmlElement user = xml.DocumentElement;
> >
> > If you want to remove the DocumentElement from the document then do
> > xml.DocumentElement.ParentNode.RemoveChild(xml.DocumentElement);
> > Then create a new element e.g.
> > XmlElement element = xml.CreateElement("Build");
> > element.SetAttribute("type", "Daily");
> > // set other attributes the same way
> > // then append element to document
> > xml.AppendChild(element);
> > // then create next element
> > XmlElement element1 = xml.CreateElement("Sync");
> > element1.SetAttribute("version", "1.0.0.0");
> > // set other attributes the same way
> > // then append element as needed e.g.
> > element.AppendChild(element1);
> >
> > With the DOM you need to do two steps, first create a node (Create...),
> > then insert it into another node (AppendChild (or InsertBefore)).
> >
> >
> > --
> >
> > Martin Honnen --- MVP XML
> >
http://JavaScript.FAQTs.com/