如何使用C#.net和xmlns属性编写XML文件。 [英] How write XML file using C#.net with xmlns attribute.
本文介绍了如何使用C#.net和xmlns属性编写XML文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须像写一样写xml文件
Hi,
I have to write xml file like the fallowing
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Status>Enabled</Status>
</VersioningConfiguration>
当我写作时我无法获得根元素上的XMLNS属性。
我找到了一些解决方案网中的离子,但我得到每个子元素的xmlns。
任何人都可以帮我写上面提到的。
谢谢,
purna
when I am writing I am unable to get the XMLNS attribute on the root element.
I have find some solution in the net but I am getting xmlns for every child elements.
can any one help me to write like above mentioned.
thanks,
purna
推荐答案
解决方案是
the solution is
using (XmlWriter writer = XmlWriter.Create(filepath))
{
XNamespace ns = "http://s3.amazonaws.com/doc/2006-03-01/";
var doc = new XDocument(
new XElement(ns + "VersioningConfiguration"));
doc.WriteTo(writer);
}
从来没有人自我宣传(到现在为止)我可以建议这个提示:
重写XML文件。
Never one to self-promote (until now) may I suggest this tip:
Rewriting XML Files.
这篇关于如何使用C#.net和xmlns属性编写XML文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文