【发布时间】:2018-04-19 07:17:42
【问题描述】:
我正在使用 C# 中的 XDocument 类编写 XML 文档。
正在尝试获取此输出:
<Details xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" p2:type="SomeStuff"></Details>
这是我尝试过的,但由于“:”而引发异常
XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
...
new XElement("Details", new XAttribute(XNamespace.Xmlns + "p2", ns), new XAttribute("p2:type", "SomeStuff"),
实现所需输出的正确方法是什么?
【问题讨论】: