private void addParameter(SensorParameterWithDate sensorParameterWithDate) { XmlDocument doc = new XmlDocument(); doc.Load(this.XmlFilePath); XmlElement b = this.createSensorWithDateParameter(sensorParameterWithDate.second, sensorParameterWithDate.minute, sensorParameterWithDate.hour, sensorParameterWithDate.day, sensorParameterWithDate.month, sensorParameterWithDate.year, sensorParameterWithDate.id, sensorParameterWithDate.name, sensorParameterWithDate.value, doc); if (verifyParameter(sensorParameterWithDate.id) == false) { XmlElement parameter = doc.CreateElement(sensorParameterWithDate.name); parameter.SetAttribute("id", sensorParameterWithDate.id); XmlNode last = doc.LastChild; last.AppendChild(parameter); parameter.AppendChild(b); } else { XmlNode nodeParam = doc.SelectSingleNode("data/" + sensorParameterWithDate.name); nodeParam.AppendChild(b); } doc.Save(this.XmlFilePath); }
public void putInDataXml(String message) { XmlDocument doc = new XmlDocument(); doc.LoadXml(message); XmlNode root = doc.SelectSingleNode("/h2o"); XmlNode parameter = doc.SelectSingleNode("/h2o/parameter"); string second = root.Attributes["second"].InnerText; string minute = root.Attributes["minute"].InnerText; string hour = root.Attributes["hour"].InnerText; string day = root.Attributes["day"].InnerText; string month = root.Attributes["month"].InnerText; string year = root.Attributes["year"].InnerText; string name = parameter.Attributes["name"].InnerText; string id = parameter["id"].InnerText; string value = parameter["value"].InnerText; SensorParameterWithDate realParameter = new SensorParameterWithDate(second, minute, hour, day, month, year, id, name, value); if (File.Exists(this.XmlFilePath) == false) { creatDataXml(realParameter); } else { addParameter(realParameter); } }
private void creatDataXml(SensorParameterWithDate sensorParameterWithDate) { XmlDocument doc = new XmlDocument(); //criar o conteudo do documento XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null); doc.AppendChild(dec); XmlElement root = doc.CreateElement("data"); XmlElement parameter = doc.CreateElement(sensorParameterWithDate.name); parameter.SetAttribute("id", sensorParameterWithDate.id); XmlElement b = this.createSensorWithDateParameter(sensorParameterWithDate.second, sensorParameterWithDate.minute, sensorParameterWithDate.hour, sensorParameterWithDate.day, sensorParameterWithDate.month, sensorParameterWithDate.year, sensorParameterWithDate.id, sensorParameterWithDate.name, sensorParameterWithDate.value, doc); doc.AppendChild(root); root.AppendChild(parameter); parameter.AppendChild(b); doc.Save(this.XmlFilePath); }