Editar

Compartilhar via


XNamespace.None Property

Definition

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; }
static member None : System.Xml.Linq.XNamespace
Public Shared ReadOnly Property None As XNamespace

Property Value

The XNamespace that corresponds to no namespace.

Examples

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

Remarks

If an element or attribute is in no namespace, its namespace will be set to the namespace returned by this property.

Applies to

See also