XmlWriter.Settingsとは? わかりやすく解説

XmlWriter.Settings プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

この XmlWriter インスタンスを作成するために使用した XmlWriterSettings オブジェクトを取得します。

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

Public Overridable ReadOnly
 Property Settings As XmlWriterSettings
Dim instance As XmlWriter
Dim value As XmlWriterSettings

value = instance.Settings
public virtual XmlWriterSettings Settings { get;
 }
public:
virtual property XmlWriterSettings^ Settings {
    XmlWriterSettings^ get ();
}
/** @property */
public XmlWriterSettings get_Settings ()
public function get Settings
 () : XmlWriterSettings

プロパティ値
このライタのインスタンスを作成するために使用した XmlWriterSettings オブジェクト。このライタが Create メソッドを使用して作成されなかった場合、このプロパティは null 参照 (Visual Basic では Nothing) を返します。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlWriterSettings クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

System.Xml.XmlWriter.Create メソッドで作成された XmlWriter オブジェクトでサポートする一連の機能を指定します。

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

Public NotInheritable Class
 XmlWriterSettings
Dim instance As XmlWriterSettings
public sealed class XmlWriterSettings
public ref class XmlWriterSettings sealed
public final class XmlWriterSettings
public final class XmlWriterSettings
解説解説
使用例使用例

XML ファイルに書き込みを行う XmlWriter を作成し、新しい行にそれぞれの属性を書き込む方法の例を次に示します。

Dim settings As XmlWriterSettings = New
 XmlWriterSettings()
settings.Indent = true
settings.OmitXmlDeclaration = true
settings.NewLineOnAttributes = true
       
writer = XmlWriter.Create(Console.Out, settings)

writer.WriteStartElement("order")
writer.WriteAttributeString("orderID", "367A54")
writer.WriteAttributeString("date", "2001-05-03")
writer.WriteElementString("price", "19.95")
writer.WriteEndElement()
    
writer.Flush()
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
       
writer = XmlWriter.Create(Console.Out, settings);

writer.WriteStartElement("order");
writer.WriteAttributeString("orderID", "367A54");
writer.WriteAttributeString("date", "2001-05-03");
writer.WriteElementString("price", "19.95");
writer.WriteEndElement();
    
writer.Flush();

このサンプルの出力は、次のようになります。

<order
  orderID="367A54"
  date="2001-05-03">
  <price>19.95</price>
</order>
継承階層継承階層
System.Object
  System.Xml.XmlWriterSettings
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlWriterSettings コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

XmlWriterSettings クラスの新しいインスタンスを初期化します。

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

Dim instance As New XmlWriterSettings
public XmlWriterSettings ()
public:
XmlWriterSettings ()
public XmlWriterSettings ()
public function XmlWriterSettings ()
解説解説

XmlWriterSettings のインスタンスの初期プロパティ値を次の表に示します。

プロパティ

初期値

CheckCharacters

true

CloseOutput

false

ConformanceLevel

Document

Encoding

Encoding.UTF8

Indent

false

IndentChars

2 個の空白

NewLineChars

\r\n (復帰、改行)

NewLineHandling

Replace

NewLineOnAttributes

false

OmitXmlDeclaration

false

使用例使用例

インデントにタブ文字を使用する XmlWriter オブジェクトを作成する例を次に示します。

Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports Microsoft.VisualBasic

Public Class Sample 

  Public Shared Sub Main()
 
  
    Dim writer As XmlWriter = Nothing

    Try 

       ' Create an XmlWriterSettings object with the correct options.
 
       Dim settings As XmlWriterSettings =
 New XmlWriterSettings()
       settings.Indent = true
       settings.IndentChars = (ControlChars.Tab)
       settings.OmitXmlDeclaration = true

       ' Create the XmlWriter object and write some content.
       writer = XmlWriter.Create("data.xml", settings)
       writer.WriteStartElement("book")
       writer.WriteElementString("item", "tesing")
       writer.WriteEndElement()
    
       writer.Flush()

      Finally
         If Not (writer Is
 Nothing) Then
            writer.Close()
         End If
      End Try

   End Sub 
End Class 
using System;
using System.IO;
using System.Xml;
using System.Text;

public class Sample {

  public static void Main()
 {
  
    XmlWriter writer = null;

    try {

       // Create an XmlWriterSettings object with the correct options.
 
       XmlWriterSettings settings = new XmlWriterSettings();
       settings.Indent = true;
       settings.IndentChars = ("\t");
       settings.OmitXmlDeclaration = true;

       // Create the XmlWriter object and write some content.
       writer = XmlWriter.Create("data.xml", settings);
       writer.WriteStartElement("book");
       writer.WriteElementString("item", "tesing");
       writer.WriteEndElement();
    
       writer.Flush();

     } 
     finally  {
        if (writer != null)
          writer.Close();
     }
  } 
} 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlWriterSettings プロパティ


XmlWriterSettings メソッド


XmlWriterSettings メンバ

System.Xml.XmlWriter.Create メソッドで作成された XmlWriter オブジェクトでサポートする一連の機能を指定します。

XmlWriterSettings データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド XmlWriterSettings XmlWriterSettings クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ OutputMethod XmlWriter 出力をシリアル化するために使用するメソッドを取得します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlWriterSettings クラス
System.Xml 名前空間



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「XmlWriter.Settings」の関連用語

XmlWriter.Settingsのお隣キーワード
検索ランキング

   

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



XmlWriter.Settingsのページの著作権

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

©2026 GRAS Group, Inc.RSS