Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML appending 1

Status
Not open for further replies.

karmafree

Programmer
May 10, 2001
107
0
0
GB
Hey,

How can I append data to an XML document?
For example, if I got an existing file
called (share.xml):

<?xml version=&quot;1.0&quot;?>

<myshare>
<share>
<name>dylan.mp3</name>
<size>7 MB</size>
<type>mp3</type>
<infolder>c:\</infolder>
</share>
</myshare>


How can I append another <share> block
using C# code?

I've tried:

XMLDocument doc = new XMLDocument(&quot;share.xml&quot;, null);
doc.LoadXml();

But get errors.

Thank you,
karmafree.

 
I don't think you can load the actual document as part of the constructor. Try:

XmlDocument doc = new XMLDocument();
FileStream myFile = new FileStream(&quot;share.xml&quot;, FileMode.Open);
doc.Load(myFile);
//do what you will here
myFile.Close();

As for how you add a new &quot;share block&quot;, perhaps try XMLNode.AppendChild().


I haven't actually done this myself, but it looks like it should work =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top