Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlTextWriter.WriteRaw Method

Writes raw markup manually.

Overload List

Writes raw markup manually from a string.

Supported by the .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);

Writes raw markup manually from a character buffer.

Supported by the .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);

Example

[Visual Basic, C#, C++] The following example writes a string using the WriteRaw method.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of WriteRaw. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

XmlTextWriter Class | XmlTextWriter Members | System.Xml Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.