Mono Class Library: System.Xml.XmlTextWriter Overview | Members

System.Xml.XmlTextWriter.WriteStartElement Method

Writes a start element with the specified name, and associates it with the given namespace and prefix. [Edit]

public override void WriteStartElement (string prefix, string localName, string namespaceUri)

Parameters

prefix
A string specifying the namespace prefix of the element. [Edit]
localName
A string specifying the local name of the element. [Edit]
namespaceUri
Documentation for this section has not yet been entered. [Edit]
prefix
Documentation for this section has not yet been entered. [Edit]

Exceptions

TypeReason
ArgumentExceptionXmlTextWriter.Namespaces is false for the writer, and prefix and ns are not both null. [Edit]
InvalidOperationExceptionThe XmlTextWriter.WriteState is WriteState.Closed. [Edit]

Remarks

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:

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).

[Edit]

Example

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.

Requirements

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