XElement root = new XElement("root"); XElement child = new XElement("child"); root.Add(child);
XElement element = new XElement("element"); element.Add(new XAttribute("attributeName", "attributeValue"));In this example, we create an XElement object called "element", and add an attribute to it using the Add method. Package library: System.Xml.Linq (required to be referenced in the project to use this namespace)