473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

adding a node in XML file

hi,
I have a xml file as shown:

<?xml version="1.0" encoding="utf-8"?>
<PIM>
<fragments>
</fragments>
</PIM>
</xml>

I must add children in the fragments node such as:

<fragments>
<element name="name1">hello</element>
<element name="name2">hello 2</element>
<element name="name3">hello 3</element>
....
<fragments>

The problem is that I am not be able to add children using XmlDocument,
XmlElement nor XmlNode...May anyone help me with this issue?

Thanks in advance
regards
Aug 21 '06 #1
6 6500
Hello, Vicente!

[skipped]

VGThe problem is that I am not be able to add children using XmlDocument,
VGXmlElement nor XmlNode...May anyone help me with this issue?

What's the problem? Give code sample, where you're trying to add children node.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Aug 21 '06 #2
Thanks for the reply Vadym

This is my snippet code:
....
XmlNode fragments = root.SelectSingleNode("fragments"); //now I am in
fragments
....//My problem is that I don't know how to declare the node element and I
didn't find that on the Web
fragments.AppendChildNode(node); //I must add nodes

Apologies if my explanation insn't enough good, This is because of my mother
tongue isn't English
Thanks a lot!
"Vadym Stetsyak" <va*****@ukr.netescribio en el mensaje
news:uX**************@TK2MSFTNGP04.phx.gbl...
Hello, Vicente!

[skipped]

VGThe problem is that I am not be able to add children using
XmlDocument,
VGXmlElement nor XmlNode...May anyone help me with this issue?

What's the problem? Give code sample, where you're trying to add children
node.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Aug 21 '06 #3


"Vicente GarcÃ*a" wrote:
hi,
I have a xml file as shown:

<?xml version="1.0" encoding="utf-8"?>
<PIM>
<fragments>
</fragments>
</PIM>
</xml>

I must add children in the fragments node such as:

<fragments>
<element name="name1">hello</element>
<element name="name2">hello 2</element>
<element name="name3">hello 3</element>
....
<fragments>

The problem is that I am not be able to add children using XmlDocument,
XmlElement nor XmlNode...May anyone help me with this issue?

Thanks in advance
regards
Vicente,
What technicial limitation prohibits you from using the XmlDocument object
to manipulate your doucment (other than the fact that this document is not
valid xml)?
Unless you can provide sound logical reasons and technical limitations there
isn't a solution for you here - only a hack.

The XmlDocument object conforms to the xml standards, unless you know
exactly what you are doing you should avoid the "I'm smarter than the
framework developers" approach to xml manipulation. Don't take offence to
this either. I've seen way to many solvable problems that people just don't
take the time to fix correctly. Some just apply a hack to get it working and
never go back. This will cause more problems in the long run.

<?xml version="1.0" encoding="utf-8"?>
<PIM>
<fragments>
</fragments>
</PIM>
</xml>
<!-- </xmlis not valid -
The <?xml version="1.0" ?is a processing instruction and is required for
all xml documents, it doesn't required any ending tag, let alone one that was
never defined.

Aug 21 '06 #4
Hello, Vicente!

VGThis is my snippet code:
VG...
VGXmlNode fragments = root.SelectSingleNode("fragments"); //now I am in
VGfragments
VG...//My problem is that I don't know how to declare the node element
VGand I didn't find that on the Web

//assume that we have XmlDocument xmlDoc

XmlElement newElement = xmlDoc.CreateElement("element");
newElment.SetAttribute("name", "nameXXX");
fragments.AppendChild(newElement );

VGApologies if my explanation insn't enough good, This is because of my
VGmother tongue isn't English

You're not alone :8-)

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Aug 21 '06 #5
Thanks a million!

I've just run it and it works fine :)
I was very confused because of the examples I found didn't serve

regards

"Vadym Stetsyak" <va*****@ukr.netescribio en el mensaje
news:O1**************@TK2MSFTNGP04.phx.gbl...
Hello, Vicente!

VGThis is my snippet code:
VG...
VGXmlNode fragments = root.SelectSingleNode("fragments"); //now I am in
VGfragments
VG...//My problem is that I don't know how to declare the node element
VGand I didn't find that on the Web

//assume that we have XmlDocument xmlDoc

XmlElement newElement = xmlDoc.CreateElement("element");
newElment.SetAttribute("name", "nameXXX");
fragments.AppendChild(newElement );

VGApologies if my explanation insn't enough good, This is because of my
VGmother tongue isn't English

You're not alone :8-)

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Aug 21 '06 #6
hi Jared
I type the last </xmlbut it isn't in my code, I didn't realize
I could use XmlDocument, in fact this is my intention but I didn't Know how
to use it in this situation because my code always failed, but now Vadim
shows me how to use it.

many thanks
regards

>
Vicente,
What technicial limitation prohibits you from using the XmlDocument object
to manipulate your doucment (other than the fact that this document is not
valid xml)?
Unless you can provide sound logical reasons and technical limitations
there
isn't a solution for you here - only a hack.

The XmlDocument object conforms to the xml standards, unless you know
exactly what you are doing you should avoid the "I'm smarter than the
framework developers" approach to xml manipulation. Don't take offence to
this either. I've seen way to many solvable problems that people just
don't
take the time to fix correctly. Some just apply a hack to get it working
and
never go back. This will cause more problems in the long run.

<?xml version="1.0" encoding="utf-8"?>
<PIM>
<fragments>
</fragments>
</PIM>
</xml>
<!-- </xmlis not valid -
The <?xml version="1.0" ?is a processing instruction and is required for
all xml documents, it doesn't required any ending tag, let alone one that
was
never defined.

Aug 21 '06 #7

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

Similar topics

1
by: serge calderara | last post by:
Dear all, I have an application which timely create log file in XML format I ma using the SystemFileWatcher object to monitor creation of new file in the proper path. So far no problem When...
2
by: Keith M | last post by:
Hi, I have found a very useful piece of code in the msdn which shows how to load an xml config file, search for a particular value and replace it. Could someone possibly convert it to C# from...
5
by: CR | last post by:
I've been to figure out how to get AddSortLast function to add nodes in acsending order (a b c d) I figured it out how to get it to sort in decending order but I can't get it to sort in acsending...
3
by: Brian Henry | last post by:
If i already have a tree view created, and want to add another new node to it, how would i do so? Is there a way to throught tags or anything? like i have this RootNode | +-- Child 1 +--...
6
by: SQACSharp | last post by:
I'm using the EnumChildWindows API with an EnumChildWndProc callback to populate the treeview. The output will be something similar to spy+ + How can I specify the parent when adding a new node...
1
by: Bart Steur | last post by:
Hi As a VB6 user I'm unfamiliar with the Treeview control of VB2005. I read it was changed but I have a hard time finding the right help/samples for my problem. In VB6 you had 1 collection,...
0
by: avolkman | last post by:
I've just begun learning XML and XPATH, so I'm currently at a very beginner level. I have an existing XML file that I would like to add an additional node to before saving it to another variable. The...
0
by: empiresolutions | last post by:
Howdy, I have an PHP page that edits XML files. I want ADD a new *id* attribute to all nodes on the page that do not have it all ready. Then i want to delete all of the values of *id* and set...
0
by: NatsoumiMaya | last post by:
hi ppl, i have a code to write in C where i have to implement the mkdir, rm, rmdir and touch functions using double linked lists...im haveing trouble with it...here is what i have so far: #ifndef...
60
by: Bill Cunningham | last post by:
I have a row of values like such, placed in a text file by fprintf. 10.50 10.25 10.00 10.75 11.00 What I want to do to the above colum is add a new column right beside it which is a total...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...
0
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
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,...

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.