次の方法で共有


XmlTextWriter.XmlSpace プロパティ

現在の xml:space スコープを表す XmlSpace を取得します。

Overrides Public ReadOnly Property XmlSpace As XmlSpace
[C#]
public override XmlSpace XmlSpace {get;}
[C++]
public: __property XmlSpace get_XmlSpace();
[JScript]
public override function get XmlSpace() : XmlSpace;

プロパティ値

現在の xml:space スコープを表す XmlSpace

説明
なし xml:space スコープが存在しない場合、これが既定値になります。
既定値 現在のスコープが xml:space="default" です。
保存 現在のスコープが xml:space="preserve" です。

解説

これにより、あるコンポーネントで、別のコンポーネントが設定したライタの状態を確認できます。

使用例

[Visual Basic, C#, C++] WriteWhitespace メソッドを使用して、ファイルを書式設定する方法を制御する例を次に示します。

 
Option Strict
Option Explicit

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        ' Create the writer.
        Dim writer As XmlTextWriter = Nothing
        writer = New XmlTextWriter("ws.html", Nothing)
        
        ' Write an element (this one is the root).
        writer.WriteStartElement("p")
        
        ' Write the xml:space attribute.
        writer.WriteAttributeString("xml", "space", Nothing, "preserve")
        
        ' Verify that xml:space is set properly.
        If writer.XmlSpace = XmlSpace.Preserve Then
            Console.WriteLine("xmlspace is correct!")
        End If 
        ' Write out the HTML elements.  Insert white space
        ' between 'something' and 'Big'.
        writer.WriteString("something")
        writer.WriteWhitespace("  ")
        writer.WriteElementString("b", "B")
        writer.WriteString("ig")
        
        ' Write the root end 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 the writer.
    XmlTextWriter writer = null;
    writer = new XmlTextWriter ("ws.html", null);

    // Write an element (this one is the root).
    writer.WriteStartElement("p");

    // Write the xml:space attribute.
    writer.WriteAttributeString("xml", "space", null, "preserve");

    // Verify that xml:space is set properly.
    if (writer.XmlSpace == XmlSpace.Preserve)
      Console.WriteLine("xmlspace is correct!");

    // Write out the HTML elements.  Insert white space
    // between 'something' and 'Big'
    writer.WriteString("something");
    writer.WriteWhitespace("  ");
    writer.WriteElementString("b", "B");
    writer.WriteString("ig");

    // Write the root end 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 the writer.
    XmlTextWriter* writer = 0;
    writer = new XmlTextWriter (S"ws.html", 0);

    // Write an element (this one is the root).
    writer->WriteStartElement(S"p");

    // Write the xml:space attribute.
    writer->WriteAttributeString(S"xml", S"space", 0, S"preserve");

    // Verify that xml:space is set properly.
    if (writer->XmlSpace == XmlSpace::Preserve)
        Console::WriteLine(S"xmlspace is correct!");

    // Write out the HTML elements.  Insert white space
    // between 'something' and 'Big'
    writer->WriteString(S"something");
    writer->WriteWhitespace(S"  ");
    writer->WriteElementString(S"b", S"B");
    writer->WriteString(S"ig");

    // Write the root end element.
    writer->WriteEndElement();
             
    // Write the XML to file and close the writer.
    writer->Close();  
  }

[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, Common Language Infrastructure (CLI) Standard

参照

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