如:xml文件:
<?xml version="1.0" encoding="utf-8"?>
<what>
<Re ID="1" max="">
<UserID>www</UserID>
<DateTime>2006-11-22 09:25:06</DateTime>
<IP>192.168.1.17</IP>
</Re>
</what>
怎样删除Re节点的max属性???(是删除此属性,不是清空属性值!!!)
好像有个Attributes.Remove方法,怎么用???
<?xml version="1.0" encoding="utf-8"?>
<what>
<Re ID="1" max="">
<UserID>www</UserID>
<DateTime>2006-11-22 09:25:06</DateTime>
<IP>192.168.1.17</IP>
</Re>
</what>
怎样删除Re节点的max属性???(是删除此属性,不是清空属性值!!!)
好像有个Attributes.Remove方法,怎么用???
{
string strXMLPath = Server.MapPath("xml文件");
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(strXMLPath);
XmlNode _node = xmldoc.SelectSingleNode("what/Re[UserID='www']");
if (_node != null)
{
_node.ParentNode.RemoveChild(_node);
}
xmldoc.Save(strXMLPath);
}
using System.IO;
using System.Xml;public class Sample
{
public static void Main()
{ XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>"); XmlElement root = doc.DocumentElement; // Remove the genre attribute.
root.RemoveAttribute("genre");
Console.WriteLine("Display the modified XML...");
Console.WriteLine(doc.InnerXml); }
}
<Re ID="1">
<UserID>www</UserID>
<DateTime>2006-11-22 09:25:06</DateTime>
<IP>192.168.1.17</IP>
</Re>
xe.RemoveAttribute("ID");//删除ID属性