Mono Class Library: System.Xml.XmlTextWriter Overview | MembersSystem.Xml.XmlTextWriter.WriteStartElement Method |
Writes a start element with the specified name, and associates it with the given namespace and prefix. [Edit]
|
Type Reason ArgumentException XmlTextWriter.Namespaces is false for the writer, and prefix and ns are not both null. [Edit] InvalidOperationException The XmlTextWriter.WriteState is WriteState.Closed. [Edit]
If ns is already in scope and has an associated prefix, the current instance will automatically write that prefix also.
If any of the input parameters are null or string.Empty, the start element is written with that parameter missing.
Note:[Edit]Write any attributes using the XmlTextWriter.WriteStartAttribute(string, string, string), XmlTextWriter.WriteString(string), and XmlTextWriter.WriteEndAttribute methods, then close the element using the XmlTextWriter.WriteEndElement method.
This method overrides XmlWriter.WriteStartElement(string, string).
This example demonstrates the XmlTextWriter.WriteStartElement(string, string, string) method, writing the XML to the console.
C# Example using System; using System.Xml; public class WriteXml { public static void Main() { XmlTextWriter xWriter = new XmlTextWriter(Console.Out); xWriter.WriteStartDocument(); xWriter.WriteStartElement("prefix","element", "namespace"); xWriter.WriteEndDocument(); } }The output is
<?xml version="1.0" encoding= "someencoding"?>
<prefix:element xmlns:prefix="namespace" />
The value of the encoding attribute is the encoding of the output stream of the console.
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0