【发布时间】:2015-06-01 17:58:31
【问题描述】:
我在 C# 中创建 xml,并希望添加 Namespace 和 Declaration 。我的xml如下:
XNamespace ns = "http://ab.com//abc";
XDocument myXML = new XDocument(
new XDeclaration("1.0","utf-8","yes"),
new XElement(ns + "Root",
new XElement("abc","1")))
这将在根级别和子元素 abc 级别添加 xmlns=""。
<Root xmlns="http://ab.com/ab">
<abc xmlns=""></abc>
</Root>
但我只希望它在根级别而不是子级别,如下所示:
<Root xmlns="http://ab.com/ab">
<abc></abc>
</Root>
以及如何在顶部添加声明,我的代码在运行后没有显示声明。
请帮我获取完整的xml作为
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Root xmlns="http://ab.com/ab">
<abc></abc>
</Root>
【问题讨论】:
标签: c# xml linq-to-xml