次の方法で共有


XmlTextWriter.WriteRaw メソッド

手動で生のマークアップを書き込みます。

オーバーロードの一覧

文字列から手動で生のマークアップを書き込みます。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Overrides Public Sub WriteRaw(String)

[C#] public override void WriteRaw(string);

[C++] public: void WriteRaw(String*);

[JScript] public override function WriteRaw(String);

文字バッファから手動で生のマークアップを書き込みます。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Overrides Public Sub WriteRaw(Char(), Integer, Integer)

[C#] public override void WriteRaw(char[], int, int);

[C++] public: void WriteRaw(__wchar_t __gc[], int, int);

[JScript] public override function WriteRaw(Char[], int, int);

使用例

[Visual Basic, C#, C++] WriteRaw メソッドを使用して文字列を書き込む例を次に示します。

[Visual Basic, C#, C++] メモ   ここでは、WriteRaw のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Option Strict
Option Explicit

Imports System
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 'Main
End Class 'Sample 

[C#] 
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();  
  }

}

[C++] 
#using <mscorlib.dll>
#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 = new XmlTextWriter (Console::Out);
     writer->Formatting = Formatting::Indented;
    
     // Write the root element.
     writer->WriteStartElement(S"Items");

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

     // Write the same string using WriteString. Note that the 
     // special characters are escaped.
     writer->WriteStartElement(S"Item");
     writer->WriteString(S"Write the same string using WriteString:  ");
     writer->WriteString(S"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();  
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

XmlTextWriter クラス | XmlTextWriter メンバ | System.Xml 名前空間