XmlTextWriter writer = new XmlTextWriter("doc.xml", Encoding.UTF8); writer.WriteStartDocument(); writer.WriteDocType("html", null, null, null); writer.WriteStartElement("html"); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close();
XmlTextWriter writer = new XmlTextWriter("doc.xml", Encoding.UTF8); writer.WriteStartDocument(); writer.WriteDocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", null); writer.WriteStartElement("html"); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close();In this example, we create an XML document with a document type declaration for the XHTML 1.0 Transitional document. The WriteDocType method is called with the document type name "html" and the SYSTEM and PUBLIC identifiers for the DTD. Package Library: The XmlTextWriter class is part of the System.Xml namespace, which is included in the .NET Framework Class Library.