XAttribute.PreviousAttribute Property returns the previous attribute of the parent element. : XAttribute « XML LINQ « C# / C Sharp






XAttribute.PreviousAttribute Property returns the previous attribute of the parent element.

 
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass{
   public static void Main(){
        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);
    }
}

   
  








Related examples in the same category

1.Using the LINQ to XML API to Create an XML Document
2.Creating an Attribute with Functional Construction
3.Creating an Attribute and Adding It to Its Element
4.XAttribute Class represents an XML attribute.
5.Create a new instance of the XAttribute class from the specified name and value.
6.Create XAttribute with namespace
7.Add XAttribute array to XElement
8.XAttribute.IsNamespaceDeclaration Property tells if this attribute is a namespace declaration.
9.XAttribute.Name Property returns the expanded name of this attribute.
10.XAttribute.NextAttribute Property returns the next attribute of the parent element.
11.XAttribute.NodeType Property returns the node type for this node.
12.XAttribute.Remove removes this attribute from its parent element.
13.XAttribute.SetValue sets the value of this attribute.
14.XAttribute.ToString converts the current XAttribute object to a string representation.
15.XAttribute.Value gets or sets the value of this attribute.
16.It is easier to use casting when the attribute might or might not exist.
17.Cast the value of this XAttribute to a Boolean.
18.Cast the value of this XAttribute to a DateTime.