XmlDocument.CreateWhitespace メソッド
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlDocument Dim text As String Dim returnValue As XmlWhitespace returnValue = instance.CreateWhitespace(text)
戻り値
新しい XmlWhitespace ノード。

このメソッドは、DOM (Document Object Model) に対する Microsoft 拡張機能です。ドキュメントを手動で書式指定するときに使用します。
このメソッドは、ドキュメントのコンテキスト内で新しいオブジェクトを作成しますが、自動的には新しいオブジェクトをドキュメント ツリーに追加しません。新しいオブジェクトを追加するには、ノード挿入メソッドのいずれか 1 つを明示的に呼び出す必要があります。

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- XmlDocument.CreateWhitespace メソッドのページへのリンク