XAttribute.IsNamespaceDeclaration 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
判斷這個屬性是否為命名空間宣告。
public:
property bool IsNamespaceDeclaration { bool get(); };
C#
public bool IsNamespaceDeclaration { get; }
member this.IsNamespaceDeclaration : bool
Public ReadOnly Property IsNamespaceDeclaration As Boolean
如果這個屬性是命名空間宣告,則為 true
,否則為 false
。
下列範例會建立命名空間宣告的屬性,以及不是 的屬性。 然後,它會使用這個屬性來顯示每個屬性是否為命名空間宣告。
C#
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屬性是否真的是命名空間宣告。
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |