System.Xml.XmlWriter.WriteStartElement Method

When overridden in a derived class, writes the specified start tag and associates it with the given namespace.

Syntax

public void WriteStartElement (string localName, string ns)

Parameters

localName
The local name of the element.
ns
The namespace URI to associate with the element. If this namespace is already in scope and has an associated prefix, the writer automatically writes that prefix also.

Exceptions

TypeReason
InvalidOperationExceptionThe XmlWriter.WriteState is WriteState.Closed.

Remarks

After calling this method you can either write attributes, or create content using XmlWriter.WriteComment(string), XmlWriter.WriteString(string), or WriteStartElement for child elements. You can close the element with either XmlWriter.WriteEndElement or XmlWriter.WriteFullEndElement. For example, the following C# code:

Example

 writer.WriteStartElement("item",null);
 writer.WriteString("some text");
 writer.WriteEndElement();

Generates the following output:

Example

 <item>some text</item>

For the asynchronous version of this method, see XmlWriter.WriteStartElementAsync(string, string).

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0