语言

XNamespace.Xml 属性

定义

XNamespace获取对应于 XML URI (http://www.w3.org/XML/1998/namespace) 的对象。

public:
 static property System::Xml::Linq::XNamespace ^ Xml { System::Xml::Linq::XNamespace ^ get(); };
public static System.Xml.Linq.XNamespace Xml { get; }
static member Xml : System.Xml.Linq.XNamespace
Public Shared ReadOnly Property Xml As XNamespace

属性值

对应于 XNamespace XML URI (http://www.w3.org/XML/1998/namespace)。

示例

以下示例演示如何在 XML 树中创建 xml:space="preserve" 属性:

XElement root = new XElement("Root",
    new XAttribute(XNamespace.Xml + "space", "preserve"),
    new XElement("Child", "content")
);
Console.WriteLine(root);
Dim root As XElement = _
    <Root xml:space="preserve">
        <Child>content</Child>
    </Root>
Console.WriteLine(root)

此示例生成以下输出:

<Root xml:space="preserve">
  <Child>content</Child>
</Root>

注解

某些标准化属性(例如 space)位于命名空间中 http://www.w3.org/XML/1998/namespace 。 W3C 标准指定此命名空间不必在 XML 树中声明为属性。 它是在 XML 分析器中始终自动可用的保留命名空间。

适用于

另请参阅