Прочетете на английски Редактиране

Споделяне чрез


XAttribute.NextAttribute Property

Definition

Gets the next attribute of the parent element.

C#
public System.Xml.Linq.XAttribute NextAttribute { get; }
C#
public System.Xml.Linq.XAttribute? NextAttribute { get; }

Property Value

An XAttribute containing the next attribute of the parent element.

Examples

The following example shows how to iterate through the attributes of an element using this property.

C#
XElement root = new XElement("Root",  
    new XAttribute("Att1", 1),  
    new XAttribute("Att2", 2),  
    new XAttribute("Att3", 3),  
    new XAttribute("Att4", 4)  
);  

XAttribute att = root.FirstAttribute;  
do {  
    Console.WriteLine(att);  
}  
while((att = att.NextAttribute) != null);  

This example produces the following output:

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

Remarks

Attributes are maintained in the XML tree in the order that they were added to the element. When a collection of attributes is returned by Attributes, they are returned in the order that they were added, and are not sorted. When you request the next attribute through this property, this property returns the attribute that was added after this attribute.

If this attribute does not have a parent, or if there is no next attribute, then this property returns null.

Applies to

Продукт Версии
.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, 8, 9, 10
.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, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also