C# 添加xml的节点
2013-02-26 14:50
260 查看
首先导入
1.添加命名空间
2.声明:
4.添加节点
5.保存
1.添加命名空间
using System.Xml;
2.声明:
private XmlDataDocument xmldoc;
3.初始化: /// <summary> /// 初始化xmldoc /// </summary> public void localxml() { xmldoc = new XmlDataDocument(); xmldoc.Load(GetMapPath("xmlfile/shezhi.xml")); }
4.添加节点
/// <summary> /// 添加xml节点。 /// </summary> public void wirtexml(string family) { localxml(); string jdid = "jp" + family; XmlNode xmlserver = xmldoc.SelectSingleNode("jiapu"); XmlElement jp_shez = xmldoc.CreateElement("jp_shezhi"); jp_shez.SetAttribute("id", jdid); XmlElement jb_up_dw = xmldoc.CreateElement("jp_up_dw"); jb_up_dw.InnerText = "100"; jp_shez.AppendChild(jb_up_dw); XmlElement jb_lt_rt = xmldoc.CreateElement("jp_lt_rt"); jb_lt_rt.InnerText = "80"; jp_shez.AppendChild(jb_lt_rt); XmlElement jb_color = xmldoc.CreateElement("jp_cl"); jb_color.InnerText = "red"; jp_shez.AppendChild(jb_color); XmlElement jb_w = xmldoc.CreateElement("jp_w"); jb_w.InnerText = "1"; jp_shez.AppendChild(jb_w); XmlElement jb_bj = xmldoc.CreateElement("jp_bj"); jb_bj.InnerText = "1"; jp_shez.AppendChild(jb_bj); XmlElement jb_action = xmldoc.CreateElement("jp_action"); jb_action.InnerText = "lt"; jp_shez.AppendChild(jb_action); XmlElement jb_line = xmldoc.CreateElement("jp_line"); jb_line.InnerText = "1"; jp_shez.AppendChild(jb_line); XmlElement po_color = xmldoc.CreateElement("po_cl"); po_color.InnerText = "red"; jp_shez.AppendChild(po_color); XmlElement po_w = xmldoc.CreateElement("po_w"); po_w.InnerText = "1"; jp_shez.AppendChild(po_w); XmlElement po_bj = xmldoc.CreateElement("po_bj"); po_bj.InnerText = "1"; jp_shez.AppendChild(po_bj); XmlElement po_lt_rt = xmldoc.CreateElement("po_lt_rt"); po_lt_rt.InnerText = "10"; jp_shez.AppendChild(po_lt_rt); XmlElement familyid = xmldoc.CreateElement("po_fid"); familyid.InnerText = family.ToString(); jp_shez.AppendChild(familyid); xmlserver.AppendChild(jp_shez); xmlsave(); }
5.保存
public void xmlsave() { xmldoc.Save(Server.MapPath(@"~/xmlfile/shezhi.xml")); }
相关文章推荐
- C# 添加,修改,删除Xml节点
- C#中对 XML节点进行添加,删除
- C# 添加,修改,删除Xml节点
- C# 生成 添加 修改 删除 XML节点操作
- C# 添加,修改,删除Xml节点
- c#设置xml内容不换行及属性xsi:nil=true的空节点添加
- c#设置xml内容不换行;添加属性为xsi:nil="true"的空节点
- C# XML 添加,修改,删除Xml节点
- C#中操作XML (节点添加,修改,删除完整版)
- C# 添加,修改,删除Xml节点
- C#中为XML节点添加属性(转)
- C#中对 XML节点进行添加,删除,查找和删除操作
- 使用XmlHelper添加节点C#代码
- 【原创】包含CDATA C#操作XML(无命名空间),添加/删除/编辑节点
- C# XML添加属性和节点
- C# XML 给xml文件添加根节点
- C# 添加、修改、删除xml节点例子
- C# 添加,修改,删除Xml节点
- C#中对 XML节点进行添加,删除,查找和删除操作
- c#设置xml内容不换行;添加属性为xsi:nil="true"的空节点