XmlTextWriter.Formatting プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlTextWriter.Formatting プロパティの意味・解説 

XmlTextWriter.Formatting プロパティ

出力書式設定方法示します

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

解説解説

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();

上記コードによって、次の出力生成されます。

 <ol> 
   <li>The big <b>E</b><i>lephant</i> walks slowly.</li>
 
 </ol>

これを 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 の定義に従って定義されます。

使用例使用例

XML フラグメント書き込む例を次に示します

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlTextWriter.Formatting プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlTextWriter.Formatting プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlTextWriter.Formatting プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XmlTextWriter.Formatting プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlTextWriter.Formatting プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS