473,503 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem creating XML file...

Hi all!

I'm trying to create this XML file:

<?xml version="1.0" encoding="utf-8" ?>
<Build type="Daily" sync="True" compile="True" assemble="True" >

<Sync version="1.0.0.0" branch="QA">
<Directories basePath="//OpicsPlus/Source/Release" />
</Sync>
</Build>

For this, I'm trying to use the code below:

private static BuildConfiguration SaveXML(XmlDocument xml, string fileName)
{
// Creates the nodelist
XmlNodeList nodeList;
XmlElement user = xml.DocumentElement;
nodeList = user.SelectNodes("//Build");

// Clear all the node
user.RemoveAll();
xml.Save(fileName);

// Creates a new element for the build configuration
XmlElement xmlBuild = xml.CreateElement("//Build");
xml.DocumentElement.AppendChild(xmlBuild);

// Navigates to this node
xml.SelectSingleNode("//Build");

xml.CreateAttribute("type");
xml.CreateAttribute("sync");
xml.CreateAttribute("compile");
xml.CreateAttribute("assemble");

// Set the attribute values for the build configuration
xmlBuild.SetAttribute("type", BuildType);
xmlBuild.SetAttribute("sync", BuildSync.ToString());
xmlBuild.SetAttribute("compile", BuildCompile.ToString());
xmlBuild.SetAttribute("assemble", BuildAssemble.ToString());

// Navigates to this node
xml.SelectSingleNode("//Build");

// Creates a new element for the sync configuration
XmlElement xmlSync = xml.CreateElement("Sync");
xml.DocumentElement.AppendChild(xmlSync);
xml.CreateAttribute("version");
xml.CreateAttribute("branch");

// Set the attribute values for the sync configuration
xmlSync.SetAttribute("version", SyncVersion);
xmlSync.SetAttribute("branch", SyncBranch);

// Navigates to this node
xml.SelectSingleNode("//Build/Sync");

// Creates a new element for the sync configuration
XmlElement xmlSyncDir = xml.CreateElement("Directories");
xml.DocumentElement.AppendChild(xmlSync);

// Set the attribute values for the sync configuration
xmlSyncDir.SetAttribute("basePath", SyncBasePath);

xml.Save(fileName);
return null;
}

But it's creating like this:

<Build>
<Build type="Daily" sync="True" compile="True" assemble="True" >

<Sync version="1.0.0.0" branch="QA">
<Directories basePath="//OpicsPlus/Source/Release" />
</Sync>
</Build>
</Build>

Anybody knows how can I remove everything and start from scratch ?

Thanks!

Eduardo

--
Eduardo de Morais Ferrari
Misys OPICS Project
Stefanini IT Solutions
White Plains, NY
Phone: (914) 821-2727
Cell: (914) 406-5027
ed*************@misys.com
Nov 12 '05 #1
6 3520
Hi all

Please read this line:

// Creates a new element for the build configuration
XmlElement xmlBuild = xml.CreateElement("Build");
xml.DocumentElement.AppendChild(xmlBuild);

Instead of

// Creates a new element for the build configuration
XmlElement xmlBuild = xml.CreateElement("//Build");
xml.DocumentElement.AppendChild(xmlBuild);

Thanks!
--
Eduardo de Morais Ferrari
Misys'''''''' OPICS Project
Stefanini IT Solutions
White Plains, NY
Phone: (914) 821-2727
Cell: (914) 406-5027
ed*************@misys.com
"Ferrari, Eduardo" wrote:
Hi all!

I'm trying to create this XML file:

<?xml version="1.0" encoding="utf-8" ?>
<Build type="Daily" sync="True" compile="True" assemble="True" >

<Sync version="1.0.0.0" branch="QA">
<Directories basePath="//OpicsPlus/Source/Release" />
</Sync>
</Build>

For this, I'm trying to use the code below:

private static BuildConfiguration SaveXML(XmlDocument xml, string fileName)
{
// Creates the nodelist
XmlNodeList nodeList;
XmlElement user = xml.DocumentElement;
nodeList = user.SelectNodes("//Build");

// Clear all the node
user.RemoveAll();
xml.Save(fileName);

// Creates a new element for the build configuration
XmlElement xmlBuild = xml.CreateElement("//Build");
xml.DocumentElement.AppendChild(xmlBuild);

// Navigates to this node
xml.SelectSingleNode("//Build");

xml.CreateAttribute("type");
xml.CreateAttribute("sync");
xml.CreateAttribute("compile");
xml.CreateAttribute("assemble");

// Set the attribute values for the build configuration
xmlBuild.SetAttribute("type", BuildType);
xmlBuild.SetAttribute("sync", BuildSync.ToString());
xmlBuild.SetAttribute("compile", BuildCompile.ToString());
xmlBuild.SetAttribute("assemble", BuildAssemble.ToString());

// Navigates to this node
xml.SelectSingleNode("//Build");

// Creates a new element for the sync configuration
XmlElement xmlSync = xml.CreateElement("Sync");
xml.DocumentElement.AppendChild(xmlSync);
xml.CreateAttribute("version");
xml.CreateAttribute("branch");

// Set the attribute values for the sync configuration
xmlSync.SetAttribute("version", SyncVersion);
xmlSync.SetAttribute("branch", SyncBranch);

// Navigates to this node
xml.SelectSingleNode("//Build/Sync");

// Creates a new element for the sync configuration
XmlElement xmlSyncDir = xml.CreateElement("Directories");
xml.DocumentElement.AppendChild(xmlSync);

// Set the attribute values for the sync configuration
xmlSyncDir.SetAttribute("basePath", SyncBasePath);

xml.Save(fileName);
return null;
}

But it's creating like this:

<Build>
<Build type="Daily" sync="True" compile="True" assemble="True" >

<Sync version="1.0.0.0" branch="QA">
<Directories basePath="//OpicsPlus/Source/Release" />
</Sync>
</Build>
</Build>

Anybody knows how can I remove everything and start from scratch ?

Thanks!

Eduardo

--
Eduardo de Morais Ferrari
Misys OPICS Project
Stefanini IT Solutions
White Plains, NY
Phone: (914) 821-2727
Cell: (914) 406-5027
ed*************@misys.com

Nov 12 '05 #2


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.Doc umentElement);
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/
Nov 12 '05 #3
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.Doc umentElement);

// 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(XmlNodeTyp e 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
ed*************@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.Doc umentElement);
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/

Nov 12 '05 #4
Hi

I solved the error using:

// Append element to document
xml.DocumentElement.AppendChild(xmlSync);

But, still is not in the format that I want...

<Sync version="1.0.0.0" branch="QA">
<Directories basePath="OpicsPlus\Source\Release1.0.0.0\QA" all="true" />
</Sync>

It's writing like this:

<Build type="System" sync="True" compile="True" assemble="True">
<Sync version="1.0.0.0" branch="QA" />
<Directories basePath="//OpicsPlus/Source/Release" />
</Build>
--
Eduardo de Morais Ferrari
Misys'''''''' OPICS Project
Stefanini IT Solutions
White Plains, NY
Phone: (914) 821-2727
Cell: (914) 406-5027
ed*************@misys.com
"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.Doc umentElement);

// 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(XmlNodeTyp e 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
ed*************@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.Doc umentElement);
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/

Nov 12 '05 #5


Ferrari, Eduardo wrote:

It blew up when tryed to add the new attribute: // Append element to document
xml.AppendChild(xmlSync); <--- BLOWS UP HERE


That is not what I have shown you, my post had

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);

you need to call AppendChild on the node into which you want to insert
the node passed as an argument so in your case you want

xmlBuild.AppendChild(xmlSync);
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #6
Alright!

Now worked. Sorry I messed up!

Thanks!

Eduardo

--
Eduardo de Morais Ferrari
Misys'''''''' OPICS Project
Stefanini IT Solutions
White Plains, NY
Phone: (914) 821-2727
Cell: (914) 406-5027
ed*************@misys.com
"Martin Honnen" wrote:


Ferrari, Eduardo wrote:

It blew up when tryed to add the new attribute:

// Append element to document
xml.AppendChild(xmlSync); <--- BLOWS UP HERE


That is not what I have shown you, my post had

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);

you need to call AppendChild on the node into which you want to insert
the node passed as an argument so in your case you want

xmlBuild.AppendChild(xmlSync);
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2971
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out...
0
2092
by: Dave Harrison | last post by:
Ok before I start, please dont mail me telling me to use a more recent version of Python, I _would_ use 2.2.x but due to an existing framework all based on using 2.1.1 I have been specifically told...
6
683
by: Club-B42 | last post by:
i've compiled my programm using command "python setup.py py2exe >1" python script works fine, but .exe version fails with =====================================================================...
1
2548
by: timothy.williams | last post by:
I'm trying to install wxPython 2.5.3.1 using Python 2.3.2 on a Fedora 2 machine. I have python in a non-standard place, but I'm using --prefix with the configure script to point to where I have...
7
2902
by: longtungd1 | last post by:
I'm currently taking a Visual C++ course. I have C++ version 6.0 on my machine. I set up a basic program per course instructions to simply create a window with default toolbar, etc., using App...
5
1263
by: יוני גולדברג | last post by:
Hi, While trying to create new directory i recieve the following error message: "System.IO.DirectoryNotFoundException: Could not find a part of the path "\\premfs16\sites". The path exists, even...
10
3983
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
13
3910
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however when i try to run the app from the .exe file that...
2
1902
by: tech tech | last post by:
Hello All, I installed postgresql 7.3.4 on HPUX PA in /usr/local/pgsql and put the libraries in /usr/local/pgsql/lib/LIB_new. During the initialization( initdb), it loads libraries (language)...
5
2353
by: dav3 | last post by:
I am by no means an ultra slick programmer and my problem solving skills.. well they leave much to be desired. That being said I have been working on the following problem for the past few days and...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.