XAttribute.IsNamespaceDeclaration 属性

定义

确定此属性是否为命名空间声明。Determines if this attribute is a namespace declaration.

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

属性值

Boolean

如果此属性为命名空间声明,则为 true;否则为 falsetrue if this attribute is a namespace declaration; otherwise false.

示例

下面的示例创建一个属性,该属性是命名空间声明和不是的属性。The following example creates an attribute that is a namespace declaration and an attribute that is not. 然后,它使用此属性来显示每个属性是否为命名空间声明。It then uses this property to display whether each attribute is a namespace declaration or not.

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  

该示例产生下面的输出:This example produces the following output:

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

注解

从技术上说,在 XML 中,命名空间声明不是正确的特性。Technically, in XML, namespace declarations are not attributes proper. 但是,大多数 XML 编程人员通常不会进行这种区分。However, this distinction is not normally made by most XML programmers. 相反,因为命名空间声明与特性具有完全相同的语法,所以大多数 XML 程序员将命名空间视为属性。Instead, because namespace declarations have exactly the same syntax as attributes, most XML programmers think of namespaces as attributes. 为了简化 LINQ to XML 编程接口,命名空间在 XML 树中表示为属性。To simplify the LINQ to XML programming interface, namespaces are represented in the XML tree as attributes. 您可以使用此属性来确定特定 LINQ to XML 特性是否确实为命名空间声明。You can use this property to determine if a particular LINQ to XML attribute is really a namespace declaration.

适用于

另请参阅