如题:现有一个XML文件a.xml如下:<?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>怎么去掉这句话 xmlns="http://www.163.com/rss/0.9"
<root xmlns="http://www.163.com/rss/0.9">
<Header>头</Header>
<Items>
<Item>
<Value>内容</Value>
</Item>
<Item>
<Value>内容</Value>
</Item>
</Items>
<Footer>脚</Footer>
</root>怎么去掉这句话 xmlns="http://www.163.com/rss/0.9"
当你家了头标签之后
当你查询的时候就变成两张表了
你可以这样
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("XMLFile1.xml"));
DataTable dt = new DataTable();
if (ds.Tables.Count != 0)
{
dt = ds.Tables[1];
}
else
{
dt = ds.Tables[0]; }
你先试试
还是去掉那个属性啊
还是<root xmlns="">
修改后得到的结果是<?xml version="1.0" encoding="utf-8"?>
<root>
<Header>头</Header>
<Items>
<Item>
<Value>内容</Value>
</Item>
<Item>
<Value>内容</Value>
</Item>
</Items>
<Footer>脚</Footer>
</root>
xmld.Load(Server.MapPath("XMLFile1.xml"));//加载
XmlNodeList list = xmld.SelectSingleNode("today").ChildNodes;//获取子节点
XmlNode node = xmld.LastChild;
XmlNode root = xmld.SelectSingleNode("today");
XmlElement xmlsub1 = xmld.CreateElement("people");
xmlsub1.SetAttribute("id", TempId);
这是我项目里德
xmlsub1.SetAttribute("id", TempId);
这个是添加xmlsub1.RemoveAllAttributes("id", TempId);
我想象这样就可以
你试试
不好用的话
xmlsub1.点下面有好几个remove什么我英文不太好
你试试肯定有好用的
写错了应该是这样
xmlsub1.RemoveAllAttributes(“id”);
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); }
}
我试了都不好使
你要忙了 帮不了你了
给你个思路你看行不行
用 //root.ReplaceChild(xml1, xmln);
用一个节点替换就的节点
我也是没有办法了
sorry
我测试删除name属性是成功的,代码和xml如下:
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>
看看这篇文章:http://blog.csdn.net/honkerhero/archive/2007/07/02/1675824.aspx
------------------------------------
当然可以。
他说Xlm标准中有泪是关键字的东西是删不掉
我猜你的xmlns就是
那个相当于关键字
是删不掉的
你换个名不行吗?
不过这样比较麻烦
最好的办法就是在你加载的时候就不要创建xmlns这个属性
//Create our own namespaces for the output
XmlSerializerNamespaces ns = new XmlSerializerNamespaces ();//Add an empty namespace and empty value
ns.Add ("", "");//Create the serializer
XmlSerializer slz = new XmlSerializer (someType);//Serialize the object with our own namespaces (notice the overload)
slz.Serialize (myXmlTextWriter, someObject, ns);
此外,在评论中还提到了去除开头的<?xml version="1.0" encoding="utf-8"?>的方法:
XmlWriterSettings settings = new XmlWriterSettings ();
settings.OmitXmlDeclaration = true; // Remove the <?xml version="1.0" encoding="utf-8"?>XmlWriter writer = XmlWriter.Create ("output_file_name.xml", settings);