# Appending xml document

**URL:** <https://forum.kirupa.com/t/appending-xml-document/257909>\
**Category:** Uncategorized\
**Created:** [April 18, 2008, 9:21am UTC](https://forum.kirupa.com/t/appending-xml-document/257909 "2008-04-18T09:21:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KAnjali](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@KAnjali](https://forum.kirupa.com/u/KAnjali)\
**Post date:** [April 18, 2008, 9:21am UTC](https://forum.kirupa.com/t/appending-xml-document/257909/1 "2008-04-18T09:21:06Z")

</div>

I want to append the existing XML document with some tags, I wrote the code but its not working . Can you please suggest me to do this.

[SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] txt = textBox1.Text.ToString();  
[/SIZE][SIZE=2][COLOR=#008080]XmlDocument[/COLOR][/SIZE][SIZE=2] xdoc = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]XmlDocument[/COLOR][/SIZE]SIZE=2;  
xdoc.LoadXml(txt);  
[/SIZE][SIZE=2][COLOR=#008080]XmlNode[/COLOR][/SIZE][SIZE=2] root = xdoc.DocumentElement;  
[/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008080]XmlElement[/COLOR][/SIZE][SIZE=2] elem = xdoc.CreateElement([/SIZE][SIZE=2][COLOR=#800000]“price”[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2]);  
elem.InnerText = [/SIZE][SIZE=2][COLOR=#800000]“19.95”[/COLOR][/SIZE][SIZE=2];[/SIZE][SIZE=2][COLOR=#008000]  
[/COLOR][/SIZE][SIZE=2]root.InsertAfter(elem, root.FirstChild);  
[/SIZE][SIZE=2]xdoc.Save(txt);

Thanks a lot,  
Anjali:jail:  
[/SIZE]

---

<div class="post-metadata">

**Author:** ![KAnjali](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@KAnjali](https://forum.kirupa.com/u/KAnjali)\
**Post date:** [May 22, 2008, 5:18am UTC](https://forum.kirupa.com/t/appending-xml-document/257909/2 "2008-05-22T05:18:47Z")

</div>

Hmm…Thanks Kiripa…  
Its done…

Thanks a lot,  
Anjali …👼

[quote=kirupa;2315552]That is similar to what I am explaining here where I add a Book node, an attribute, and child nodes: [http://www.kirupa.com/net/writingXML\_pg2.htm](http://www.kirupa.com/net/writingXML_pg2.htm)

Have you had a chance to look through that?

Thanks,  
Kirupa[/quote]
