Freigeben über


XmlDocument.CreateWhitespace-Methode

Erstellt einen XmlWhitespace-Knoten.

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

Syntax

'Declaration
Public Overridable Function CreateWhitespace ( _
    text As String _
) As XmlWhitespace
'Usage
Dim instance As XmlDocument
Dim text As String
Dim returnValue As XmlWhitespace

returnValue = instance.CreateWhitespace(text)
public virtual XmlWhitespace CreateWhitespace (
    string text
)
public:
virtual XmlWhitespace^ CreateWhitespace (
    String^ text
)
public XmlWhitespace CreateWhitespace (
    String text
)
public function CreateWhitespace (
    text : String
) : XmlWhitespace

Parameter

  • text
    Die Zeichenfolge darf nur die Zeichen  
 
 und 	 enthalten.

Rückgabewert

Ein neuer XmlWhitespace-Knoten.

Hinweise

Diese Methode ist eine Microsoft-Erweiterung des Dokumentobjektmodells (Document Object Model, DOM). Sie wird verwendet, wenn Sie das Dokument manuell formatieren möchten.

Obwohl diese Methode das neue Objekt im Kontext des Dokuments erstellt, wird es nicht automatisch der Dokumentstruktur hinzugefügt. Rufen Sie eine der Methoden zum Einfügen von Knoten explizit auf, um das neue Objekt hinzuzufügen.

Beispiel

Im folgenden Beispiel wird dem Dokument Leerraum hinzugefügt.

Option Explicit
Option Strict

Imports System
Imports System.Xml
Imports Microsoft.VisualBasic

Public Class Sample
    
    Public Shared Sub Main()

        Dim doc As New XmlDocument()
        doc.LoadXml("<author>" & _
                    "<first-name>Eva</first-name>" & _
                    "<last-name>Corets</last-name>" & _
                    "</author>")
            
        Console.WriteLine("InnerText before...")
        Console.WriteLine(doc.DocumentElement.InnerText)
            
        ' Add white space.    
        Dim currNode as XmlNode = doc.DocumentElement
        Dim ws As XmlWhitespace = doc.CreateWhitespace(ControlChars.CrLf)
        currNode.InsertAfter(ws, currNode.FirstChild)
            
        Console.WriteLine()
        Console.WriteLine("InnerText after...")
        Console.WriteLine(doc.DocumentElement.InnerText)
        
    End Sub 
End Class 'Sample
using System;
using System.Xml;

public class Sample {

  public static void Main() {

      XmlDocument doc = new XmlDocument();
      doc.LoadXml("<author>" +
                  "<first-name>Eva</first-name>"+
                  "<last-name>Corets</last-name>" + 
                  "</author>"); 
        
      Console.WriteLine("InnerText before...");
      Console.WriteLine(doc.DocumentElement.InnerText);

      // Add white space.     
      XmlNode currNode=doc.DocumentElement;
      XmlWhitespace ws = doc.CreateWhitespace("\r\n");
      currNode.InsertAfter(ws, currNode.FirstChild);

      Console.WriteLine();
      Console.WriteLine("InnerText after...");
      Console.WriteLine(doc.DocumentElement.InnerText);

  } 
}
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<author><first-name>Eva</first-name><last-name>Corets</last-name></author>" );
   Console::WriteLine( "InnerText before..." );
   Console::WriteLine( doc->DocumentElement->InnerText );
   
   // Add white space.     
   XmlNode^ currNode = doc->DocumentElement;
   XmlWhitespace^ ws = doc->CreateWhitespace( "\r\n" );
   currNode->InsertAfter( ws, currNode->FirstChild );
   Console::WriteLine();
   Console::WriteLine( "InnerText after..." );
   Console::WriteLine( doc->DocumentElement->InnerText );
}
import System.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<author>"
                    + "<first-name>Eva</first-name>"
                    + "<last-name>Corets</last-name>"
                    + "</author>");

        Console.WriteLine("InnerText before...");
        Console.WriteLine(doc.get_DocumentElement().get_InnerText());

        // Add white space.     
        XmlNode currNode = doc.get_DocumentElement();
        XmlWhitespace ws = doc.CreateWhitespace("\r\n");
        currNode.InsertAfter(ws, currNode.get_FirstChild());

        Console.WriteLine();
        Console.WriteLine("InnerText after...");
        Console.WriteLine(doc.get_DocumentElement().get_InnerText());
    } //main
} //Sample

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlDocument-Klasse
XmlDocument-Member
System.Xml-Namespace