利用XmlDocument对象去创建
具体代码如下:
XmlDocument xmlDoc = new XmlDocument();
XmlElement rootElment = xmlDoc.CreateElement("root");//root根节点
XmlElement dataNode = xmlDoc.CreateElement("Data");子节点
XmlElement graphNode = xmlDoc.CreateElement("graph");
graphNode.SetAttribute("caption", "查询统计");//给graph节点添加属性
graphNode.SetAttribute("xAxisName", "全部");//给graph节点添加属性
graphNode.SetAttribute("yAxisName", "次数");//给graph节点添加属性
XmlElement row = xmlDoc.CreateElement("row");
row.SetAttribute("Name", "张三");
row.SetAttribute("IPAdress", "192.168.0.1");
row.SetAttribute("PCName", "ZhangSan_pc"));
dataNode.AppendChild(row);
rootElment.AppendChild(Data);
rootElment.AppendChild(graphNode);
xmlDoc.AppendChild(rootElment);