473,569 Members | 2,557 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 BuildConfigurat ion SaveXML(XmlDocu ment xml, string fileName)
{
// Creates the nodelist
XmlNodeList nodeList;
XmlElement user = xml.DocumentEle ment;
nodeList = user.SelectNode s("//Build");

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

// Creates a new element for the build configuration
XmlElement xmlBuild = xml.CreateEleme nt("//Build");
xml.DocumentEle ment.AppendChil d(xmlBuild);

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

xml.CreateAttri bute("type");
xml.CreateAttri bute("sync");
xml.CreateAttri bute("compile") ;
xml.CreateAttri bute("assemble" );

// Set the attribute values for the build configuration
xmlBuild.SetAtt ribute("type", BuildType);
xmlBuild.SetAtt ribute("sync", BuildSync.ToStr ing());
xmlBuild.SetAtt ribute("compile ", BuildCompile.To String());
xmlBuild.SetAtt ribute("assembl e", BuildAssemble.T oString());

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

// Creates a new element for the sync configuration
XmlElement xmlSync = xml.CreateEleme nt("Sync");
xml.DocumentEle ment.AppendChil d(xmlSync);
xml.CreateAttri bute("version") ;
xml.CreateAttri bute("branch");

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

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

// Creates a new element for the sync configuration
XmlElement xmlSyncDir = xml.CreateEleme nt("Directories ");
xml.DocumentEle ment.AppendChil d(xmlSync);

// Set the attribute values for the sync configuration
xmlSyncDir.SetA ttribute("baseP ath", SyncBasePath);

xml.Save(fileNa me);
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 3530
Hi all

Please read this line:

// Creates a new element for the build configuration
XmlElement xmlBuild = xml.CreateEleme nt("Build");
xml.DocumentEle ment.AppendChil d(xmlBuild);

Instead of

// Creates a new element for the build configuration
XmlElement xmlBuild = xml.CreateEleme nt("//Build");
xml.DocumentEle ment.AppendChil d(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 BuildConfigurat ion SaveXML(XmlDocu ment xml, string fileName)
{
// Creates the nodelist
XmlNodeList nodeList;
XmlElement user = xml.DocumentEle ment;
nodeList = user.SelectNode s("//Build");

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

// Creates a new element for the build configuration
XmlElement xmlBuild = xml.CreateEleme nt("//Build");
xml.DocumentEle ment.AppendChil d(xmlBuild);

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

xml.CreateAttri bute("type");
xml.CreateAttri bute("sync");
xml.CreateAttri bute("compile") ;
xml.CreateAttri bute("assemble" );

// Set the attribute values for the build configuration
xmlBuild.SetAtt ribute("type", BuildType);
xmlBuild.SetAtt ribute("sync", BuildSync.ToStr ing());
xmlBuild.SetAtt ribute("compile ", BuildCompile.To String());
xmlBuild.SetAtt ribute("assembl e", BuildAssemble.T oString());

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

// Creates a new element for the sync configuration
XmlElement xmlSync = xml.CreateEleme nt("Sync");
xml.DocumentEle ment.AppendChil d(xmlSync);
xml.CreateAttri bute("version") ;
xml.CreateAttri bute("branch");

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

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

// Creates a new element for the sync configuration
XmlElement xmlSyncDir = xml.CreateEleme nt("Directories ");
xml.DocumentEle ment.AppendChil d(xmlSync);

// Set the attribute values for the sync configuration
xmlSyncDir.SetA ttribute("baseP ath", SyncBasePath);

xml.Save(fileNa me);
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 BuildConfigurat ion SaveXML(XmlDocu ment xml, string fileName)
{
// Creates the nodelist
XmlNodeList nodeList;
XmlElement user = xml.DocumentEle ment;


If you want to remove the DocumentElement from the document then do
xml.DocumentEle ment.ParentNode .RemoveChild(xm l.DocumentEleme nt);
Then create a new element e.g.
XmlElement element = xml.CreateEleme nt("Build");
element.SetAttr ibute("type", "Daily");
// set other attributes the same way
// then append element to document
xml.AppendChild (element);
// then create next element
XmlElement element1 = xml.CreateEleme nt("Sync");
element1.SetAtt ribute("version ", "1.0.0.0");
// set other attributes the same way
// then append element as needed e.g.
element.AppendC hild(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.DocumentEle ment.ParentNode .RemoveChild(xm l.DocumentEleme nt);

// Create a new element for the build configuration
XmlElement xmlBuild = xml.CreateEleme nt("Build");
xmlBuild.SetAtt ribute("type", BuildType);
xmlBuild.SetAtt ribute("sync", BuildSync.ToStr ing());
xmlBuild.SetAtt ribute("compile ", BuildCompile.To String());
xmlBuild.SetAtt ribute("assembl e", BuildAssemble.T oString());

// Append element to document
xml.AppendChild (xmlBuild);

// Creates a new element for the sync configuration
XmlElement xmlSync = xml.CreateEleme nt("Sync");

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

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

Unhandled Exception: System.InvalidO perationExcepti on: This document already
has a DocumentElement node.
at System.Xml.XmlD ocument.IsValid ChildType(XmlNo deType type)
at System.Xml.XmlN ode.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 BuildConfigurat ion SaveXML(XmlDocu ment xml, string fileName)
{
// Creates the nodelist
XmlNodeList nodeList;
XmlElement user = xml.DocumentEle ment;


If you want to remove the DocumentElement from the document then do
xml.DocumentEle ment.ParentNode .RemoveChild(xm l.DocumentEleme nt);
Then create a new element e.g.
XmlElement element = xml.CreateEleme nt("Build");
element.SetAttr ibute("type", "Daily");
// set other attributes the same way
// then append element to document
xml.AppendChild (element);
// then create next element
XmlElement element1 = xml.CreateEleme nt("Sync");
element1.SetAtt ribute("version ", "1.0.0.0");
// set other attributes the same way
// then append element as needed e.g.
element.AppendC hild(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.DocumentEle ment.AppendChil d(xmlSync);

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

<Sync version="1.0.0. 0" branch="QA">
<Directories basePath="Opics Plus\Source\Rel ease1.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.DocumentEle ment.ParentNode .RemoveChild(xm l.DocumentEleme nt);

// Create a new element for the build configuration
XmlElement xmlBuild = xml.CreateEleme nt("Build");
xmlBuild.SetAtt ribute("type", BuildType);
xmlBuild.SetAtt ribute("sync", BuildSync.ToStr ing());
xmlBuild.SetAtt ribute("compile ", BuildCompile.To String());
xmlBuild.SetAtt ribute("assembl e", BuildAssemble.T oString());

// Append element to document
xml.AppendChild (xmlBuild);

// Creates a new element for the sync configuration
XmlElement xmlSync = xml.CreateEleme nt("Sync");

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

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

Unhandled Exception: System.InvalidO perationExcepti on: This document already
has a DocumentElement node.
at System.Xml.XmlD ocument.IsValid ChildType(XmlNo deType type)
at System.Xml.XmlN ode.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 BuildConfigurat ion SaveXML(XmlDocu ment xml, string fileName)
{
// Creates the nodelist
XmlNodeList nodeList;
XmlElement user = xml.DocumentEle ment;


If you want to remove the DocumentElement from the document then do
xml.DocumentEle ment.ParentNode .RemoveChild(xm l.DocumentEleme nt);
Then create a new element e.g.
XmlElement element = xml.CreateEleme nt("Build");
element.SetAttr ibute("type", "Daily");
// set other attributes the same way
// then append element to document
xml.AppendChild (element);
// then create next element
XmlElement element1 = xml.CreateEleme nt("Sync");
element1.SetAtt ribute("version ", "1.0.0.0");
// set other attributes the same way
// then append element as needed e.g.
element.AppendC hild(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.CreateEleme nt("Build");
element.SetAttr ibute("type", "Daily");
// set other attributes the same way
// then append element to document
xml.AppendChild (element);
// then create next element
XmlElement element1 = xml.CreateEleme nt("Sync");
element1.SetAtt ribute("version ", "1.0.0.0");
// set other attributes the same way
// then append element as needed e.g.
element.AppendC hild(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.Append Child(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.CreateEleme nt("Build");
element.SetAttr ibute("type", "Daily");
// set other attributes the same way
// then append element to document
xml.AppendChild (element);
// then create next element
XmlElement element1 = xml.CreateEleme nt("Sync");
element1.SetAtt ribute("version ", "1.0.0.0");
// set other attributes the same way
// then append element as needed e.g.
element.AppendC hild(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.Append Child(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
2976
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 "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google....
0
2096
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 to use 2.1.1 to avoid any crossover issues/problems. Thanks ;-) So ... Using gcc Im compiling Python2.1.1, and it configures quite reasonably,...
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 ===================================================================== D:\\Scripts\B-4-2\la2luncher\dist>la2launcher.exe Traceback (most recent call last): File "la2launcher.py", line 9, in ? File "config.pyc", line 11,...
1
2555
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 everything. The make install in $WXDIR seemed to go fine. I have the libxw* libraries in my lib/ directory libwx_base-2.5.so@ ...
7
2907
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 Wizard and ran build from the menu to create the .exe. Got following output: --------------------Configuration: sam - Win32...
5
1271
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 when i check the path with the code: Directory.Exists(...) the result is true. Here is the code: http://www.adeo.co.il/test.aspx
10
3999
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 application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms,...
13
3918
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 .NET creates i get the following error message: "An unhandled exception of type 'System.IO.FileNotFoundException' occurred in VisioTimeline.exe
2
1908
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) from /usr/local/pgsql/lib. In postgresql version 7.3.1, libraries are not loaded and no such problem during initdb. I had the following problem: ...
5
2366
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 have yet to find a solution. My program is supposed to read in a txt file which contains 2 lines of numbers. Program reads the file and stores each...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
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.