XNamespace.None 属性

定义

获取不与命名空间对应的 XNamespace 对象。

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

属性值

不与命名空间对应的 XNamespace

示例

下面的示例演示如何使用此属性来确定哪些元素不位于命名空间中。

XNamespace aw = "http://www.adventure-works.com";

XElement root = new XElement("Root",
    new XElement(aw + "ChildInNamespace", "content"),
    new XElement("ChildInNoNamespace", "content")
);

if (root.Name.Namespace == XNamespace.None)
    Console.WriteLine("Root element is in no namespace");
else
    Console.WriteLine("Root element is in a namespace");

if (root.Element(aw + "ChildInNamespace").Name.Namespace == XNamespace.None)
    Console.WriteLine("ChildInNamespace element is in no namespace");
else
    Console.WriteLine("ChildInNamespace element is in a namespace");

if (root.Element("ChildInNoNamespace").Name.Namespace == XNamespace.None)
    Console.WriteLine("ChildInNoNamespace element is in no namespace");
else
    Console.WriteLine("ChildInNoNamespace element is in a namespace");
Imports <xmlns:aw="http://www.adventure-works.com">

Module Module1
    Sub Main()
        Dim root As XElement = _
            <Root>
                <aw:ChildInNamespace>content</aw:ChildInNamespace>
                <ChildInNoNamespace>content</ChildInNoNamespace>
            </Root>

        If (root.Name.Namespace Is XNamespace.None) Then
            Console.WriteLine("Root element is in no namespace")
        Else
            Console.WriteLine("Root element is in a namespace")
        End If

        If (root.Element(GetXmlNamespace(aw) + "ChildInNamespace") _
                .Name.Namespace Is XNamespace.None) Then
            Console.WriteLine("ChildInNamespace element is in no namespace")
        Else
            Console.WriteLine("ChildInNamespace element is in a namespace")
        End If

        If (root.Element("ChildInNoNamespace") _
                .Name.Namespace Is XNamespace.None) Then
            Console.WriteLine("ChildInNoNamespace element is in no namespace")
        Else
            Console.WriteLine("ChildInNoNamespace element is in a namespace")
        End If
    End Sub
End Module

该示例产生下面的输出:

Root element is in no namespace
ChildInNamespace element is in a namespace
ChildInNoNamespace element is in no namespace

注解

如果元素或特性不位于命名空间中,则其命名空间将设置为此属性返回的命名空间。

适用于

另请参阅