XmlTextWriter writer = new XmlTextWriter("output.xml", null); writer.WriteStartElement("Person"); writer.WriteElementString("Name", "John"); writer.WriteElementString("Age", "30"); writer.WriteEndElement(); writer.Close();
XmlTextWriter writer = new XmlTextWriter(Console.Out); writer.Formatting = Formatting.Indented; writer.WriteStartElement("Document"); writer.WriteElementString("Title", "My Document"); writer.WriteElementString("Content", "Some text here."); writer.WriteEndElement(); writer.Close();This code creates an XmlTextWriter object that writes the XML to the console output. It sets the Formatting property to Indented to make the output more readable. It then writes a