XmlTextWriter.Formatting プロパティ
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlTextWriter Dim value As Formatting value = instance.Formatting instance.Formatting = value
public Formatting Formatting { get; set; }
public: property Formatting Formatting { Formatting get (); void set (Formatting value); }
/** @property */ public Formatting get_Formatting () /** @property */ public void set_Formatting (Formatting value)
Formatting 値の 1 つ。既定値は Formatting.None (特定の書式設定なし) です。

![]() |
---|
Microsoft .NET Framework version 2.0 リリースでは、System.Xml.XmlWriter.Create メソッドと XmlWriterSettings クラスを使用して XmlWriter インスタンスを作成することをお勧めします。これにより、このリリースで導入されたすべての新機能を十分に活用できます。詳細については、「XML ライタの作成」を参照してください。 |
Indented オプションを設定すると、子要素には Indentation プロパティと IndentChar プロパティを使用してインデント幅が適用されます。要素の内容だけにインデント幅が適用されます。混合コンテンツを含む HTML 要素を書き込む C# コードを次に示します。
XmlTextWriter w = new XmlTextWriter(Console.Out); w.Formatting = Formatting.Indented; w.WriteStartElement("ol"); w.WriteStartElement("li"); w.WriteString("The big "); // This means "li" now has a mixed content model. w.WriteElementString("b", "E"); w.WriteElementString("i", "lephant"); w.WriteString(" walks slowly."); w.WriteEndElement(); w.WriteEndElement();
これを HTML で表示すると、太字要素と斜体要素の間に空白は入りません。この例では、これらの要素の間にインデントを追加すると、単語 "Elephant" が不適切な位置で分割されます。
![]() |
---|
String.Empty を含むテキストを書き込むと、その要素は混合コンテンツ モードになります。子要素は、この "混合" モード ステータスを継承しません。"混合" 要素の子要素は、子要素も "混合" コンテンツを含むのでない限り、インデント幅が適用されます。要素の内容 (http://www.w3.org/TR/1998/REC-xml-19980210#sec-element-content) および混合コンテンツ (http://www.w3.org/TR/1998/REC-xml-19980210#sec-mixed-content) は、これらの用語の XML 1.0 の定義に従って定義されます。 |

Option Explicit Option Strict Imports System Imports System.IO Imports System.Xml Public Class Sample Public Shared Sub Main() 'Create a writer to write XML to the console. Dim writer As XmlTextWriter = Nothing writer = New XmlTextWriter(Console.Out) 'Use indentation for readability. writer.Formatting = Formatting.Indented writer.Indentation = 4 'Write an element (this one is the root). writer.WriteStartElement("book") 'Write the title element. writer.WriteStartElement("title") writer.WriteString("Pride And Prejudice") writer.WriteEndElement() 'Write the close tag for the root element. writer.WriteEndElement() 'Write the XML to file and close the writer. writer.Close() End Sub 'Main End Class 'Sample
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { //Create a writer to write XML to the console. XmlTextWriter writer = null; writer = new XmlTextWriter (Console.Out); //Use indentation for readability. writer.Formatting = Formatting.Indented; writer.Indentation = 4; //Write an element (this one is the root). writer.WriteStartElement("book"); //Write the title element. writer.WriteStartElement("title"); writer.WriteString("Pride And Prejudice"); writer.WriteEndElement(); //Write the close tag for the root element. writer.WriteEndElement(); //Write the XML to file and close the writer. writer.Close(); } }
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { //Create a writer to write XML to the console. XmlTextWriter^ writer = nullptr; writer = gcnew XmlTextWriter( Console::Out ); //Use indentation for readability. writer->Formatting = Formatting::Indented; writer->Indentation = 4; //Write an element (this one is the root). writer->WriteStartElement( "book" ); //Write the title element. writer->WriteStartElement( "title" ); writer->WriteString( "Pride And Prejudice" ); writer->WriteEndElement(); //Write the close tag for the root element. writer->WriteEndElement(); //Write the XML to file and close the writer. writer->Close(); }
import System.*; import System.IO.*; import System.Xml.*; public class Sample { public static void main(String[] args) { //Create a writer to write XML to the console. XmlTextWriter writer = null; writer = new XmlTextWriter(Console.get_Out()); //Use indentation for readability. writer.set_Formatting(Formatting.Indented); writer.set_Indentation(4); //Write an element (this one is the root). writer.WriteStartElement("book"); //Write the title element. writer.WriteStartElement("title"); writer.WriteString("Pride And Prejudice"); writer.WriteEndElement(); //Write the close tag for the root element. writer.WriteEndElement(); //Write the XML to file and close the writer. writer.Close(); } //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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からXmlTextWriter.Formatting プロパティを検索する場合は、下記のリンクをクリックしてください。

- XmlTextWriter.Formatting プロパティのページへのリンク