共用方式為


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

備註

如果專案或屬性不在命名空間中,其命名空間將會設定為這個屬性所傳回的命名空間。

適用於

另請參閱