XmlDocument.CreateWhitespace(String) メソッド

定義

XmlWhitespace ノードを作成します。

public:
 virtual System::Xml::XmlWhitespace ^ CreateWhitespace(System::String ^ text);
public virtual System.Xml.XmlWhitespace CreateWhitespace (string text);
public virtual System.Xml.XmlWhitespace CreateWhitespace (string? text);
abstract member CreateWhitespace : string -> System.Xml.XmlWhitespace
override this.CreateWhitespace : string -> System.Xml.XmlWhitespace
Public Overridable Function CreateWhitespace (text As String) As XmlWhitespace

パラメーター

text
String

文字列には、次の文字  と のみを含める必要があります。

戻り値

新しい XmlWhitespace ノード。

次の使用例は、文書に空白を追加します。

#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 );
}

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);
  }
}
Option Explicit
Option Strict

Imports System.Xml

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

注釈

このメソッドは、ドキュメント オブジェクト モデル (DOM) に対する Microsoft の拡張機能です。 ドキュメントの書式を手動で設定する場合に使用されます。

このメソッドはドキュメントのコンテキストで新しいオブジェクトを作成しますが、新しいオブジェクトをドキュメント ツリーに自動的に追加することはありません。 新しいオブジェクトを追加するには、ノード挿入メソッドのいずれかを明示的に呼び出す必要があります。

適用対象