创建XML节点
我想创建形如如下格式的xml文档。
<temperature>
<max></max>
<min></min>
<average></average>
</temperature>
用下面代码创建:
//XML气温节点
XmlElement temNode=meteorologyParaDBXML .CreateElement ("temperature");
rootDistrict.AppendChild(temNode);
XmlElement element = meteorologyParaDBXML.CreateElement("max");
temNode.AppendChild(element);
element = meteorologyParaDBXML.CreateElement("min");
temNode.AppendChild(element);
element = meteorologyParaDBXML.CreateElement("average");
temNode.AppendChild(element);
运行后为:
<temperature>
<max />
<min />
<average />
</temperature>
我该怎么去修改才能达到我的目的
------解决方案--------------------
element = meteorologyParaDBXML.CreateElement("min");
element.InnerText = "";
应该可以
XmlDocument meteorologyParaDBXML = new XmlDocument();
XmlElement temNode = meteorologyParaDBXML.CreateElement("temperature");
meteorologyParaDBXML.AppendChild(temNode);
XmlElement element = meteorologyParaDBXML.CreateElement("max");
element.InnerText = "";
temNode.AppendChild(element);
element = meteorologyParaDBXML.CreateElement("min");
element.InnerText = "";
temNode.AppendChild(element);
element = meteorologyParaDBXML.CreateElement("average");
element.InnerText = "";
temNode.AppendChild(element);
meteorologyParaDBXML.Save("x:\\x.xml")