XDocument.WriteTo(XmlWriter) XDocument.WriteTo(XmlWriter) XDocument.WriteTo(XmlWriter) XDocument.WriteTo(XmlWriter) Method

定義

このドキュメントを XmlWriter に書き込みます。Write this document to an XmlWriter.

public:
 override void WriteTo(System::Xml::XmlWriter ^ writer);
public override void WriteTo (System.Xml.XmlWriter writer);
override this.WriteTo : System.Xml.XmlWriter -> unit
Public Overrides Sub WriteTo (writer As XmlWriter)

パラメーター

writer
XmlWriter XmlWriter XmlWriter XmlWriter

このメソッドの書き込み対象の XmlWriterAn XmlWriter into which this method will write.

XDocumentをに書き込む方法を次の例に示します。XmlWriterThe following example shows how to write an XDocument to an XmlWriter. この例では、XML 宣言が書き込まれていないことに注意してください。Note that the example did not write an XML declaration.

StringBuilder sb = new StringBuilder();  
XmlWriterSettings xws = new XmlWriterSettings();  
xws.OmitXmlDeclaration = true;  
xws.Indent = true;  

using (XmlWriter xw = XmlWriter.Create(sb, xws))  
{  
    XDocument doc = new XDocument(  
        new XElement("Child",  
            new XElement("GrandChild", "some content")  
        )  
    );  
    doc.WriteTo(xw);  
}  

Console.WriteLine(sb.ToString());  
Dim sb As StringBuilder = New StringBuilder()  
Dim xws As XmlWriterSettings = New XmlWriterSettings()  
xws.OmitXmlDeclaration = True  
xws.Indent = True  

Using xw = XmlWriter.Create(sb, xws)  
    Dim doc As XDocument = New XDocument(<Child><GrandChild>some content</GrandChild></Child>)  
    doc.WriteTo(xw)  
End Using  

Console.WriteLine(sb.ToString())  

この例を実行すると、次の出力が生成されます。This example produces the following output:

<Child>  
  <GrandChild>some content</GrandChild>  
</Child>  

適用対象

こちらもご覧ください