Compartir a través de


XNamespace.None Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the XNamespace object that corresponds to no namespace.

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

Syntax

'Declaration
Public Shared ReadOnly Property None As XNamespace
public static XNamespace None { get; }

Property Value

Type: System.Xml.Linq.XNamespace
The XNamespace that corresponds to no namespace.

Remarks

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

Examples

The following example shows uses this property to determine which elements are in no namespace.

'add the following line to the the Imports section:
'Imports <xmlns:aw="https://www.adventure-works.com">
Dim output As New StringBuilder
Dim root As XElement = _
    <Root>
        <aw:ChildInNamespace>content</aw:ChildInNamespace>
        <ChildInNoNamespace>content</ChildInNoNamespace>
    </Root>

If (root.Name.Namespace Is XNamespace.None) Then
    output.Append("Root element is in no namespace")
    output.Append(Environment.NewLine)
Else
    output.Append("Root element is in a namespace")
    output.Append(Environment.NewLine)
End If

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

OutputTextBlock.Text = output.ToString()
StringBuilder output = new StringBuilder();
XNamespace aw = "https://www.adventure-works.com";

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

if (root.Name.Namespace == XNamespace.None)
    output.Append("Root element is in no namespace" + Environment.NewLine);
else
    output.Append("Root element is in a namespace" + Environment.NewLine);

if (root.Element(aw + "ChildInNamespace").Name.Namespace == XNamespace.None)
    output.Append("ChildInNamespace element is in no namespace" + Environment.NewLine);
else
    output.Append("ChildInNamespace element is in a namespace" + Environment.NewLine);

OutputTextBlock.Text = output.ToString();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.