XNamespace.None 属性

定义

获取不与命名空间对应的 XNamespace 对象。Gets the XNamespace object that corresponds to no namespace.

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

属性值

XNamespace

不与命名空间对应的 XNamespaceThe XNamespace that corresponds to no namespace.

示例

下面的示例演示如何使用此属性来确定不在命名空间中的元素。The following example shows uses this property to determine which elements are in no namespace.

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  

此示例生成以下输出:This example produces the following output:

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

注解

如果元素或属性不在命名空间中,则其命名空间将设置为此属性返回的命名空间。If an element or attribute is in no namespace, its namespace will be set to the namespace returned by this property.

适用于

另请参阅