using System.Xml; // Create the root element XmlElement rootElement = new XmlElement("Root"); // Add child elements to the root element XmlElement childElement1 = new XmlElement("Child1"); XmlElement childElement2 = new XmlElement("Child2"); rootElement.AppendChild(childElement1); rootElement.AppendChild(childElement2);
using System.Xml; // Create the root element XmlElement rootElement = new XmlElement("Root"); // Set the value of the root element rootElement.InnerText = "Hello, world!"; // Retrieve the value of the root element string value = rootElement.InnerText;In this example, we create an XmlElement called "Root" and set its value to "Hello, world!" using the InnerText property. We then retrieve the value of the root element using the same property. The package library for this class is System.Xml, which is part of the .NET Framework.