关于asp.net向XML循环插入节点的问题并节点含有多属性的问题
请教各位大神<?xml version="1.0" encoding="utf-8" ?>
<graph caption='爱疯' xAxisName='王斐' yAxisName='范文芳' decimalPrecision='0' formatNumberScale='0'>
<set name ='sss' value='32'></set>
<set name ='大' value='32'></set>
<set name ='发疯' value='222'></set>
</graph>
我这里有一个类似这样的XML,加载的时候要获取graph 节点,并且向graph节点里面的多个属性赋值
然后查询出一张表,循环添加到子节点<set name ='sss' value='32'></set>里面去。
怎么做啊,求教了 --------------------编程问答--------------------
XmlDocument doc = new XmlDocument();
doc.Load("c:\\temp\\1.txt");
XmlNode node = doc.DocumentElement;
node.Attributes["caption"].Value = "abc";
node.Attributes["xAxisName"].Value = "abc";
增加也是类似,创建新的XmlNode,然后DocumentElement添加进去,不会去看帮助 --------------------编程问答--------------------
DataTable dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
String path = "../ScaleMapInfo/Data.xml";
XmlDocument xml = new XmlDocument();
xml.Load(path);
XmlElement graph = xml.CreateElement("graph");
graph.SetAttribute("caption", "标题");
graph.SetAttribute("xAxisName", "横向标题");
graph.SetAttribute("yAxisName", "纵向标题");
xml.AppendChild(graph);
for (int i = 0; i < dt.Rows.Count; i++)
{
XmlElement node = xml.CreateElement("set");
node.SetAttribute("name", dt.Rows[i]["name"].ToString());
node.SetAttribute("value", dt.Rows[i]["value"].ToString());
graph.AppendChild(node);
}
我是这样写的,不知道有没有问题
补充:.NET技术 , ASP.NET