【发布时间】:2012-05-23 23:25:45
【问题描述】:
我必须创建一个 xml 文件,其中包含具有以下属性的元素:
<element
xsi:schemaLocation="http://test.xsd"
xmlns="http://test2"
xmlns:xsi=http://test3>
我试过了:
XNamespace ns = "xsi";
var root = new XElement("element",
new XAttribute(ns + "schemaLocation", "http://test.xsd"), // (I)
new XAttribute(XNamespace.Xmlns, "http://test2"), // (II)
new XAttribute(XNamespace.Xmlns + "xsi", "http://test3"), // (III)
但唯一生成好的是(III):
xmlns:xsi=http://test3
(I) 生成如下:
p1:schemaLocation="http://test.xsd" xmlns:p1="xsi"
并且 (II) 没有生成,因为该行没有编译。
知道如何生成这些属性吗?
谢谢你, 升
编辑 - 也在这里找到它:Creating XML with namespaces and schemas from an XElement
【问题讨论】:
标签: c# xml namespaces xelement xattribute