edit .xml

Hi... Me and my School mates are having an experiment where we have to note down the data for each time... (the assigment is; exersice and note down, pulse, temprature, and so on....)

And so i thought i can use C#.net and xml for this, and then display the data using xsl....

But how can i ADD tags with data to an existing .xml file?

so say i have this xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
<input>
<date>X</date>
<pulse>X</pulse>
<temp>X</temp>
<timer>X</time>
</input>
</data>

the by a form (text boxes and labels and stuf) enter data and make it like this... (still the same file)

<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
<input>
<date>X</date>
<pulse>X</pulse>
<temp>X</temp>
<timer>X</time>
</input>
<input>
<date>Ydate>
<pulse>Y</pulse>
<temp>Y</temp>
<timer>Y</time>
</input>
</data>
and then keep on going, adding more data and so on...
And PLEASE make it reall simple, no fancy error exceptions....

just real simple.... INPUT DATA, OPEN XML FILE, WRITE NEW DATA TO FILE, CLOSE FILE & PROGRAM :D

thanks in advance if some one helps me on this...

[1434 byte] By [Andreas-Moe] at [2007-12-17]
# 1

Take a look at the documentation for the XmlDocument class. You simply need to instantiate it, call the Load method, do your data manipulations (see AppendChild method documentation for an example) and then call the Save method.

MarkSh at 2007-9-8 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 2
ok.. im just a student, and did not understand that...
Andreas-Moe at 2007-9-8 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 3


XmlDocument doc = new XmlDocument();

doc.Load(@"c:\temp.xml");

XmlElement newElem = doc.CreateElement("input");

XmlElement subElem = doc.CreateElement("date");

subElem.InnerXml = "1/1/2005";

newElem.AppendChild(subElem);

doc.DocumentElement.AppendChild(newElem);

doc.Save(@"c:\temp.xml");


MarkSh at 2007-9-8 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified