XmlTextWriter.WriteRaw 方法

定义

手动写入原始标记。

重载

WriteRaw(Char[], Int32, Int32)

从字符缓冲区手动写入原始标记。

WriteRaw(String)

从字符串手动写入原始标记。

注解

备注

从 .NET Framework 2.0 开始,建议使用 XmlWriter.Create 方法和 XmlWriterSettings 类创建XmlWriter实例,以利用新功能。

WriteRaw(Char[], Int32, Int32)

Source:
XmlTextWriter.cs
Source:
XmlTextWriter.cs
Source:
XmlTextWriter.cs

从字符缓冲区手动写入原始标记。

public:
 override void WriteRaw(cli::array <char> ^ buffer, int index, int count);
public override void WriteRaw (char[] buffer, int index, int count);
override this.WriteRaw : char[] * int * int -> unit
Public Overrides Sub WriteRaw (buffer As Char(), index As Integer, count As Integer)

参数

buffer
Char[]

包含要写入的文本的字符数组。

index
Int32

缓冲区中的位置,指示要写入文本的起始位置。

count
Int32

要写入的字符数。

例外

buffernull

indexcount 小于零。

- 或 -

缓冲区长度减去 index 小于 count

注解

备注

从 .NET Framework 2.0 开始,建议使用 XmlWriter.Create 方法和 XmlWriterSettings 类创建XmlWriter实例,以利用新功能。

此方法不转义特殊字符。

重要

XmlTextWriter不会验证传递给 WriteRaw 方法的任何数据。 不应将任意数据传递给此方法。

适用于

WriteRaw(String)

Source:
XmlTextWriter.cs
Source:
XmlTextWriter.cs
Source:
XmlTextWriter.cs

从字符串手动写入原始标记。

public:
 override void WriteRaw(System::String ^ data);
public override void WriteRaw (string data);
override this.WriteRaw : string -> unit
Public Overrides Sub WriteRaw (data As String)

参数

data
String

包含要写入的文本的字符串。

示例

以下示例使用 WriteRaw 方法写入字符串。

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   // Create a writer that outputs to the console.
   XmlTextWriter^ writer = gcnew XmlTextWriter( Console::Out );
   writer->Formatting = Formatting::Indented;
   
   // Write the root element.
   writer->WriteStartElement( "Items" );
   
   // Write a string using WriteRaw. Note that the special
   // characters are not escaped.
   writer->WriteStartElement( "Item" );
   writer->WriteString( "Write unescaped text:  " );
   writer->WriteRaw( "this & that" );
   writer->WriteEndElement();
   
   // Write the same string using WriteString. Note that the 
   // special characters are escaped.
   writer->WriteStartElement( "Item" );
   writer->WriteString( "Write the same string using WriteString:  " );
   writer->WriteString( "this & that" );
   writer->WriteEndElement();
   
   // Write the close tag for the root element.
   writer->WriteEndElement();
   
   // Write the XML to file and close the writer.
   writer->Close();
}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
     // Create a writer that outputs to the console.
     XmlTextWriter writer = new XmlTextWriter (Console.Out);
     writer.Formatting = Formatting.Indented;

     // Write the root element.
     writer.WriteStartElement("Items");

     // Write a string using WriteRaw. Note that the special
     // characters are not escaped.
     writer.WriteStartElement("Item");
     writer.WriteString("Write unescaped text:  ");
     writer.WriteRaw("this & that");
     writer.WriteEndElement();

     // Write the same string using WriteString. Note that the
     // special characters are escaped.
     writer.WriteStartElement("Item");
     writer.WriteString("Write the same string using WriteString:  ");
     writer.WriteString("this & that");
     writer.WriteEndElement();

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

     // Write the XML to file and close the writer.
     writer.Close();
  }
}
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        ' Create a writer that outputs to the console.
        Dim writer As New XmlTextWriter(Console.Out)
        writer.Formatting = Formatting.Indented
        
        ' Write the root element.
        writer.WriteStartElement("Items")
        
        ' Write a string using WriteRaw. Note that the special
        ' characters are not escaped.
        writer.WriteStartElement("Item")
        writer.WriteString("Write unescaped text:  ")
        writer.WriteRaw("this & that")
        writer.WriteEndElement()
        
        ' Write the same string using WriteString. Note that the 
        ' special characters are escaped.
        writer.WriteStartElement("Item")
        writer.WriteString("Write the same string using WriteString:  ")
        writer.WriteString("this & that")
        writer.WriteEndElement()
        
        ' Write the close tag for the root element.
        writer.WriteEndElement()
        
        ' Write the XML to file and close the writer.
        writer.Close()
    End Sub
End Class

注解

备注

从 .NET Framework 2.0 开始,建议使用 XmlWriter.Create 方法和 XmlWriterSettings 类创建XmlWriter实例,以利用新功能。

此方法不转义特殊字符。

重要

XmlTextWriter不会验证传递给 WriteRaw 方法的任何数据。 不应将任意数据传递给此方法。

适用于