show your code, did you use the right XPath?? string sFile = Server.MapPath("TreeNode.xml");
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(sFile);
XmlNode node = xmldoc.SelectSingleNode("//TreeNode[@id='oos']");
if (node != null)
{
XmlElement ele = xmldoc.CreateElement("TreeNode");
XmlAttribute att = xmldoc.CreateAttribute("Text");
att.Value = "hello world";
ele.Attributes.Append(att); att = xmldoc.CreateAttribute("id");
att.Value = "ppf";
ele.Attributes.Append(att);
node.AppendChild(ele);
}
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(sFile);
XmlNode node = xmldoc.SelectSingleNode("//TreeNode[@id='oos']");
if (node != null)
{
XmlElement ele = xmldoc.CreateElement("TreeNode");
XmlAttribute att = xmldoc.CreateAttribute("Text");
att.Value = "hello world";
ele.Attributes.Append(att); att = xmldoc.CreateAttribute("id");
att.Value = "ppf";
ele.Attributes.Append(att);
node.AppendChild(ele);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货