Hello,
Im trying to update(measurement values from serial port) data from array to .xml file. The .xml file consists of sensor nodes which have child nodes: value, description and id. Only value nodes needs to be updated.
The code I have "achieved" so far only works if there is only one
The code... looks like this at the moment, please comment...
private void xmlWrite()
{
System.Xml.XmlDocument xmldoc = new
System.Xml.XmlDocument();
int id = 0;
xmldoc.Load("C:\\data2.xml");
System.Xml.XmlNode nood = xmldoc.SelectSingleNode("sensor");
foreach (System.Xml.XmlNode node in nood)
{
if (node.Name == "value")
{
node.InnerXml = arData[id];
id++;
}
}
xmldoc.Save("E:\\test3.xml");
}
I tried to add foreach-loop before the "System.Xml.XmlNode" and +id after "sensor", but it only gave always some "null reference error"...
The .xml file looks like this(form of the content can also be changed if eases the saving procedure):
Mike HankeyPosted May 18, 2008, 10:24 AM
private void xmlWrite()
{
System.Xml.XmlDocument xmldoc = new
System.Xml.XmlDocument();
int id = 0;
xmldoc.Load("C:\\data2.xml");
System.Xml.XmlNode nood = xmldoc.SelectSingleNode("sensor");
foreach (System.Xml.XmlNode node in nood)
{
node["value"].innerText = arData[id];
id++;
}
xmldoc.Save("E:\\test3.xml");
}
Mike