XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("book"); XmlAttribute attr = doc.CreateAttribute("isbn"); attr.Value = "123456789"; root.Attributes.Append(attr);
XmlDocument doc = new XmlDocument(); doc.Load("books.xml"); XmlElement root = doc.DocumentElement; XmlAttribute attr = root.Attributes["isbn"]; string isbn = attr.Value;In this example, we load an XML document from a file and retrieve the root element. We then use the Attributes property to retrieve the isbn attribute and get its value. Package library: System.Xml.dll.