The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlWriter.WriteStartElement Method (String, String, String)

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

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

public abstract void WriteStartElement (
	string prefix,
	string localName,
	string ns
public abstract void WriteStartElement (
	String prefix, 
	String localName, 
	String ns
public abstract function WriteStartElement (
	prefix : String, 
	localName : String, 
	ns : String
Not applicable.



The namespace prefix of the element.


The local name of the element.


The namespace URI to associate with the element.

Exception typeCondition


The writer is closed.

The following example writes out an XML fragment.

using System;
using System.IO;
using System.Xml;
 public class Sample
   private const string m_Document = "sampledata.xml";
   public static void Main() {
      XmlWriter writer = null;

      try {
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        writer = XmlWriter.Create (m_Document, settings);
        writer.WriteComment("sample XML fragment");
        // Write an element (this one is the root).
        // Write the namespace declaration.
        writer.WriteAttributeString("xmlns", "bk", null, "urn:samples");
        // Write the genre attribute.
        writer.WriteAttributeString("genre", "novel");
        // Write the title.
        writer.WriteString("The Handmaid's Tale");
        // Write the price.
        writer.WriteElementString("price", "19.95");
        // Lookup the prefix and write the ISBN element.
        string prefix = writer.LookupPrefix("urn:samples");
        writer.WriteStartElement(prefix, "ISBN", "urn:samples");

        // Write the style element (shows a different way to handle prefixes).
        writer.WriteElementString("style", "urn:samples", "hardcover");
        // Write the close tag for the root element.
        // Write the XML to file and close the writer.

      finally {
        if (writer != null)

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft