XAttribute.PreviousAttribute プロパティ

定義

親要素の前の属性を取得します。

public:
 property System::Xml::Linq::XAttribute ^ PreviousAttribute { System::Xml::Linq::XAttribute ^ get(); };
public System.Xml.Linq.XAttribute PreviousAttribute { get; }
public System.Xml.Linq.XAttribute? PreviousAttribute { get; }
member this.PreviousAttribute : System.Xml.Linq.XAttribute
Public ReadOnly Property PreviousAttribute As XAttribute

プロパティ値

親要素の前の属性を格納している XAttribute

次の例は、このプロパティを使用して要素の属性を反復処理する方法を示しています。

XElement root = new XElement("Root",  
    new XAttribute("Att1", 1),  
    new XAttribute("Att2", 2),  
    new XAttribute("Att3", 3),  
    new XAttribute("Att4", 4)  
);  
XAttribute att = root.LastAttribute;  
do {  
    Console.WriteLine(att);  
}  
while((att = att.PreviousAttribute) != null);  
Dim root As XElement = <Root Att1="1" Att2="2" Att3="3" Att4="4"/>  
Dim att As XAttribute = root.LastAttribute  
Dim val As Boolean = True  
Do  
    Console.WriteLine(att)  
    att = att.PreviousAttribute  
Loop While (Not (att Is Nothing))  

この例を実行すると、次の出力が生成されます。

Att4="4"  
Att3="3"  
Att2="2"  
Att1="1"  

注釈

属性は、要素に追加された順序で XML ツリーに保持されます。 属性のコレクションが によって Attributes返されると、属性は追加された順序で返され、並べ替えられません。 このプロパティを使用して前の属性を要求すると、このプロパティは、この属性の前に追加された属性を返します。

この属性に親がない場合、またはこの属性が最初の属性である場合、このプロパティは を返します null

クラスは XElement 、その属性を 1 つのリンクされたオブジェクトの XAttribute リストとして格納します。 つまり、 プロパティは PreviousAttribute 、 要素に属する属性のリストを走査する必要があります。 したがって、このプロパティを使用すると、パフォーマンスに影響を与える可能性があります。

適用対象

こちらもご覧ください