110,539
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://www.163.com/rss/0.9">
<Header>头</Header>
<Items>
<Item>
<Value>内容</Value>
</Item>
<Item>
<Value>内容</Value>
</Item>
</Items>
<Footer>脚</Footer>
</root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<Header>头</Header>
<Items>
<Item>
<Value>内容</Value>
</Item>
<Item>
<Value>内容</Value>
</Item>
</Items>
<Footer>脚</Footer>
</root>
XmlDocument doc = new XmlDocument();
doc.Load("d://messager.xml");
XmlElement root = doc.DocumentElement;
root.RemoveAttribute("name");
// root.RemoveAttribute("xmlns");
doc.Save("d://messager.xml");
<?xml version="1.0" encoding="utf-8"?>
<root name="xx" xmlns="http://www.163.com/rss/0.9">
<Header>头</Header>
<Items>
<Item>
<Value>内容</Value>
</Item>
<Item>
<Value>内容</Value>
</Item>
</Items>
<Footer>脚</Footer>
</root>
using System;
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);
}
}