#includeusing namespace std; using namespace XmlWriter; int main(){ XmlWriter writer("mydoc.xml"); //Begin writing the XML document writer.StartDocument(); //Add an element writer.AddElement("root"); //Add attributes to the element writer.AddAttribute("name", "my-root-element"); //Add a sub-element writer.AddElement("child", "Hello World!"); //End the document writer.EndDocument(); //Close the file stream writer.Close(); return 0; }
#includeIn the first example, an XML document is created with a root element and a child element containing "Hello World!" text. In the second example, elements and attributes are added using different methods such as `AddAttribute` and `StartElement`. These examples show the ease of use and flexibility of the XmlWriter library in creating XML documents.using namespace std; using namespace XmlWriter; int main(){ XmlWriter writer("mydoc.xml"); //Begin writing the XML document writer.StartDocument(); //Add an element writer.AddElement("root"); //Add attributes to the element writer.AddAttribute("name", "my-root-element"); writer.AddAttribute("size", "10"); //Add a sub-element with inner text writer.AddElement("child", "Hello World!"); //Add a sub-element with attributes writer.StartElement("child2"); writer.AddAttribute("name", "my-child-element"); writer.AddAttribute("size", "5"); writer.WriteEndElement(); //End the document writer.EndDocument(); //Close the file stream writer.Close(); return 0; }