XAttribute.IsNamespaceDeclaration 屬性

定義

判斷這個屬性是否為命名空間宣告。

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

屬性值

Boolean

如果這個屬性是命名空間宣告,則為 true,否則為 false

範例

下列範例會建立命名空間宣告的屬性,以及不是 的屬性。 然後,它會使用這個屬性來顯示每個屬性是否為命名空間宣告。

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  

這個範例會產生下列輸出:

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

備註

在技術上,在 XML 中,命名空間宣告不是適當的屬性。 不過,大部分 XML 程式設計人員通常不會進行這項區別。 相反地,因為命名空間宣告與屬性完全相同,所以大部分的 XML 程式設計人員都會將命名空間視為屬性。 為了簡化LINQ to XML程式設計介面,命名空間會在 XML 樹狀結構中表示為屬性。 您可以使用這個屬性來判斷特定LINQ to XML屬性是否真的是命名空間宣告。

適用於

另請參閱