删除命名空间xmlns:kk =" kk"来自XML数据 [英] Remove namespace xmlns:kk="kk" from XML data
本文介绍了删除命名空间xmlns:kk =" kk"来自XML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi
我创建了一个XML文件,但其中一个节点正在添加命名空间引用,我似乎无法将其删除。只添加到第一个元素/节点。
代码
Hi
I have created an XML file, however 1 of the nodes is adding a namespace reference and I cant seem to remove it. Only adds to first element/node.
Code
XmlDocument doc =doc.Load(System.Configuration.ConfigurationManager.AppSettings["doctemploc"]);
XmlElement Blaett = doc.CreateElement("kk:Blaett","kk");
XmlAttribute numbber = doc.CreateAttribute("number");
Blaett.Attributes.Append(numbber);
我尝试过:
What I have tried:
nummer.RemoveAttribute("xmlns:kk");
nummer.Attributes().Where(a => a.IsNamespaceDeclaration).Remove()
nummer.Attributes("xmlns").Remove();
推荐答案
如果您不想在输出中使用命名空间,则不要指定命名空间。
替换:
If you don't want the namespace in the output, then don't specify a namespace.
Replace:
XmlElement Blaett = doc.CreateElement("kk:Blaett","kk");
with:
XmlElement Blaett = doc.CreateElement("Blaett");
NB:对于XML文档而言,如果不声明命名空间,则使用名称空间前缀是否无效。
NB: Is it not valid for an XML document to use a namespace prefix without declaring the namespace.
感谢您的回复....我使用上面生成的文件对其进行了验证,但是失败了......它寻找前缀为命名空间....
Thanks for reply....I validated the file against it generated with above and it failed... its looking for prefixed with namespace....
这篇关于删除命名空间xmlns:kk =" kk"来自XML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文