XML添加节点问题,急! 本帖最后由 nofc2006 于 2010-07-19 17:18:56 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 XmlNode root = xmlDoc.SelectSingleNode("User"); //查找<MailTo> XmlElement xe1 = xmlDoc.CreateElement("name"); //创建一个<name>节点 xe1.SetAttribute("genre", name); //设置该节点genre属性 if (root.SelectSingleNode(@"//name[@genre='" + name + "']") == null) //判断该节点是否在XML中存在 { root.AppendChild(xe1); //添加到<MailTo>节点中 xmlDoc.Save("xxx.xml"); //写入 } xnf.AppendChild(new XmlElement();//这是添加目标节点的xnf.SetAttribute(节点属性名,属性值);//添加属性值 XmlElement公开的构造方法,不能new的. XmlElement newElmt = XmlConfig.CreateElement(NodeName);newElmt.InnerText = "note1";xnf.AppendChild(newElmt);//添加子节点 如何将pdf中表格按原始相对位置转到excel中? 100分问个条形码问题! 新浪、网易有没有让客户通过编程发送手机短信的服务吗 如何给网页上的安全控件类型的textbox赋值? c#自定义控件 winform进度条的问题 新手求助 请教 如何进行液体流动模拟?? sql的函数编写 求助命名空间System.web.mail问题 工作问题高手速速帮忙 请那位高手大哥发些C#程序的小例子给我
XmlElement xe1 = xmlDoc.CreateElement("name"); //创建一个<name>节点
xe1.SetAttribute("genre", name); //设置该节点genre属性
if (root.SelectSingleNode(@"//name[@genre='" + name + "']") == null) //判断该节点是否在XML中存在
{
root.AppendChild(xe1); //添加到<MailTo>节点中
xmlDoc.Save("xxx.xml"); //写入
}
xnf.SetAttribute(节点属性名,属性值);//添加属性值
XmlElement公开的构造方法,不能new的.
newElmt.InnerText = "note1";
xnf.AppendChild(newElmt);//添加子节点