// Create an XML element XElement bookElement = new XElement("book"); // Add a child element to the book element bookElement.Add(new XElement("title", "The Great Gatsby")); // Output the XML element as a string Console.WriteLine(bookElement.ToString());
// Create an XML element XElement bookElement = new XElement("book"); // Add an attribute to the book element bookElement.Add(new XAttribute("year", "1925")); // Output the XML element as a string Console.WriteLine(bookElement.ToString());
// Create an XML element XElement titleElement = new XElement("title"); // Add a text node to the title element titleElement.Add("The Great Gatsby"); // Output the XML element as a string Console.WriteLine(titleElement.ToString());This code creates an XML element called "title" and adds a text node with the value "The Great Gatsby". The output will be "