我得到一个空 xmlns=""
XML 树中 XElemenet 中的属性。
当我将其命名空间设置为文档命名空间时,如下所示:
string xmlns="FreeForm/SchemaDescription";
XNamespace ana = xmlns;
XElement interactiveRootTag = new XElement(ana + "InteractiveRootTag");
空
xmlns=""
不再存在,但是这个 XElement 的所有子元素,得到空 xmlns=""
.有任何想法吗?
最佳答案
您必须以这种方式添加子元素:
string xmlns="FreeForm/SchemaDescription";
XNamespace ana = xmlns;
XElement interactiveRootTag = new XElement(ana + "InteractiveRootTag");
interactiveRootTag.Add(new XElement(ana + "ChildElement",
new XAttribute("attribute","AttributeValue")));
像这样获得 XML
<InteractiveRootTag xmlns="FreeForm/SchemaDescription">
<ChildElement attribute="AttributeValue" />
</InteractiveRootTag>
关于c# - 将命名空间设置为 XElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26734032/