XAttribute.IsNamespaceDeclaration Eigenschaft

Definition

Bestimmt, ob es sich bei diesem Attribut um eine Namespacedeklaration handelt.

public:
 property bool IsNamespaceDeclaration { bool get(); };
public bool IsNamespaceDeclaration { get; }
member this.IsNamespaceDeclaration : bool
Public ReadOnly Property IsNamespaceDeclaration As Boolean

Eigenschaftswert

true wenn es sich bei diesem Attribut um eine Namespacedeklaration handelt; andernfalls false.

Beispiele

Im folgenden Beispiel wird ein Attribut erstellt, das eine Namespacedeklaration und kein Attribut ist. Anschließend wird diese Eigenschaft verwendet, um anzuzeigen, ob jedes Attribut eine Namespacedeklaration ist oder nicht.

XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root",
    new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
    new XAttribute(aw + "Att", "content")
);

foreach (XAttribute att in root.Attributes()) {
    if (att.IsNamespaceDeclaration)
        Console.WriteLine("{0} is a namespace declaration", att.Name);
    else
        Console.WriteLine("{0} is not a namespace declaration", att.Name);
}
Dim root As XElement = <aw:Root xmlns:aw='http://www.adventure-works.com'
                           aw:Att='content'/>

For Each att As XAttribute In root.Attributes()
    If (att.IsNamespaceDeclaration) Then
        Console.WriteLine("{0} is a namespace declaration", att.Name)
    Else
        Console.WriteLine("{0} is not a namespace declaration", att.Name)
    End If
Next

Dieses Beispiel erzeugt die folgende Ausgabe:

{http://www.w3.org/2000/xmlns/}aw is a namespace declaration
{http://www.adventure-works.com}Att is not a namespace declaration

Hinweise

Technisch gesehen sind Namespacedeklarationen in XML nicht ordnungsgemäß. Diese Unterscheidung wird jedoch normalerweise nicht von den meisten XML-Programmierern gemacht. Da Namespacedeklarationen stattdessen genau dieselbe Syntax wie Attribute aufweisen, denken die meisten XML-Programmierer an Namespaces als Attribute. Um die LINQ to XML-Programmierschnittstelle zu vereinfachen, werden Namespaces in der XML-Struktur als Attribute dargestellt. Mit dieser Eigenschaft können Sie ermitteln, ob ein bestimmtes LINQ to XML-Attribut wirklich eine Namespacedeklaration ist.

Gilt für:

Weitere Informationen