次の方法で共有


XmlDocument.CreateWhitespace メソッド

XmlWhitespace ノードを作成します。

Public Overridable Function CreateWhitespace( _
   ByVal text As String _) As XmlWhitespace
[C#]
public virtual XmlWhitespace CreateWhitespace(stringtext);
[C++]
public: virtual XmlWhitespace* CreateWhitespace(String* text);
[JScript]
public function CreateWhitespace(
   text : String) : XmlWhitespace;

パラメータ

  • text
    文字列には、、
、
、および 	 の文字だけを含める必要があります。

戻り値

新しい XmlWhitespace ノード。

解説

このメソッドは、DOM (Document Object Model) に対する Microsoft 拡張機能です。ドキュメントを手動で書式指定するときに使用します。

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

使用例

[Visual Basic, C#, C++] ドキュメントに空白を追加する例を次に示します。

 
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

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

  } 
}

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

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

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

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