473,403 Members | 2,354 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,403 software developers and data experts.

Append to XML?

Hi,

I use VS 2005.
How would I append XML elements to the end of an existing XML file
programmatically?
Jan 16 '06 #1
2 1304
"Amjad" <Am***@discussions.microsoft.com> schrieb:
I use VS 2005.
How would I append XML elements to the end of an existing XML file
programmatically?


Take a look at the 'XmlDocument' class and other classes in the 'System.Xml'
namespace.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 16 '06 #2

"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
:
: Hi,
:
: I use VS 2005.
: How would I append XML elements to the end of an existing XML file
: programmatically?
Assume you have the following xml document in a file named Tree.xml:

<Root>
<Branch>
<Leaf/>
<Leaf/>
</Branch>
<Branch>
<Leaf/>
</Branch>
</Root>

And let's assume you want to add a <Graft /> node to this tree so that the
end result looks like this:

<Root>
<Branch>
<Leaf/>
<Leaf/>
</Branch>
<Branch>
<Leaf/>
</Branch>
<Graft/>
</Root>
Here is one approach you can take:

Imports System.XML

'...

Dim TreeXml As XMLDocument
Dim graftNode As XMLNode

TreeXml = New XMLDocument
TreeXml.Load("Tree.xml")

graftNode = TreeXml.CreateElement("Graft")
TreeXml.selectSingleNode("/Root").AppendChild(graftNode)

Console.WriteLine(TreeXml.InnerXMl)

This will generate the following output:

<Root>
<Branch>
<Leaf />
<Leaf />
</Branch>
<Branch>
<Leaf />
</Branch>
<Graft />
</Root>

HTH
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Jan 17 '06 #3

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

Similar topics

9
by: cody | last post by:
Why isn't there an StringBuilder.Append() overload with a StringBuilder as argument? Is there a reason that I missed?
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
9
by: JMCN | last post by:
hi- i have inherited an access 97 database that keeps track of the loans. i have been running into referential intergrity problems when i try to append new loans to table. first of all is a...
1
by: David Barger | last post by:
Greetings, It appears that an Append Query I run in Access XP is randomly failing to append a field. I have payroll data being entered into a payroll database. This data is exported daily to...
5
by: Michael C via AccessMonster.com | last post by:
Hello, I have a table that I am appending 3 seperate tables into. My main problem is that each time I append the data, it simply adds to the data already there. That might sound ok, except that...
0
by: audleman | last post by:
I have an ASP form on my website where a visitor enters information. On submit, the form calls a stored procedure stores in a MS SQL 2000 database. The stored procedure works most of the time, but...
26
by: John Salerno | last post by:
If I want to create a list of the form (where each item is repeated twice after the first one), how might I do that most efficiently? Right now I have this: series = for x in range(10): ...
2
by: jeremito | last post by:
I have created a class that inherits from the list object. I want to override the append function to allow my class to append several copies at the same time with one function call. I want to do...
10
by: HYRY | last post by:
I have the following questions, I am using Python 2.4.2 19167152 #1 11306608 #1 1. the address of a.append and list.append is different, can I get the address of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.