System.Xml.XmlWriter.WriteStartElement 方法 (String)

方法描述

当在派生类中被重写时,写出具有指定的本地名称的开始标记。

语法定义(C# System.Xml.XmlWriter.WriteStartElement 方法 (String) 的用法)

public void WriteStartElement(
	string localName
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
localName System-String 元素的本地名称。
返回值 void

提示和注释

System.Xml.XmlWriter.WriteStartElement 方法 (String)例子

下面的示例编写一个 XML 节点。

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

     // Create a writer to write XML to the console.
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Indent = true;
     settings.OmitXmlDeclaration = true;
     XmlWriter writer = XmlWriter.Create(Console.Out, settings);

     // Write the book element.
     writer.WriteStartElement("book");

     // Write the title element.
     writer.WriteStartElement("title");
     writer.WriteString("Pride And Prejudice");
     writer.WriteEndElement();

     // Write the close tag for the root element.
     writer.WriteEndElement();

     // Write the XML and close the writer.
     writer.Close();  

  }
}

异常

异常 异常描述
InvalidOperationException 编写器已关闭。
EncoderFallbackException 缓冲区中有一个字符是有效的 XML 字符,但对于输出编码是无效的。 例如,如果输出编码为 ASCII,应该仅对元素和特性名使用从 0 到 127 范围内的字符。 无效的字符可能位于此方法的参数中,或者位于以前要写入缓冲区的方法的参数中。 如果可能,此类字符将使用字符实体引用进行转义(例如,在文本节点或特性值中)。 但是,不允许在元素名、特性名、注释、处理指令和 CDATA 节中使用字符实体引用。

命名空间

namespace: System.Xml

程序集: System.Xml(在 System.Xml.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1 受以下版本支持:

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。