XNode.WriteTo(XmlWriter) XNode.WriteTo(XmlWriter) XNode.WriteTo(XmlWriter) XNode.WriteTo(XmlWriter) Method

定義

このノードを XmlWriter に書き込みます。Writes this node to an XmlWriter.

public:
 abstract void WriteTo(System::Xml::XmlWriter ^ writer);
public abstract void WriteTo (System.Xml.XmlWriter writer);
abstract member WriteTo : System.Xml.XmlWriter -> unit
Public MustOverride Sub WriteTo (writer As XmlWriter)

パラメーター

writer
XmlWriter XmlWriter XmlWriter XmlWriter

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

次の例では、作成、XmlWriterに書き込まれる、StringBuilderします。The following example creates an XmlWriter that writes to a StringBuilder. このメソッドを使用して、ライターに 2 つの XML ツリーを作成します。It then uses this method to write two XML trees to the writer.

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

using (XmlWriter xw = XmlWriter.Create(sb, xws)) {  
    xw.WriteStartElement("Root");  
    XElement child1 = new XElement("Child",  
        new XElement("GrandChild", "some content")  
    );  
    child1.WriteTo(xw);  
    XElement child2 = new XElement("AnotherChild",  
        new XElement("GrandChild", "different content")  
    );  
    child2.WriteTo(xw);  
    xw.WriteEndElement();  
}  
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)  
    xw.WriteStartElement("Root")  
    Dim child1 As XElement = <Child>  
                                 <GrandChild>some content</GrandChild>  
                             </Child>  
    child1.WriteTo(xw)  
    Dim child2 As XElement = <AnotherChild>  
                                 <GrandChild>different content</GrandChild>  
                             </AnotherChild>  
    child2.WriteTo(xw)  
    xw.WriteEndElement()  
End Using  

Console.WriteLine(sb.ToString())  

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

<Root>  
  <Child>  
    <GrandChild>some content</GrandChild>  
  </Child>  
  <AnotherChild>  
    <GrandChild>different content</GrandChild>  
  </AnotherChild>  
</Root>  

注釈

このメソッドを使用して、コードは非常に大きなドキュメントのストリーミング変換を記述することができます。You can use this method to write code that does a streaming transform of a very large document. 詳細については、「方法 :大きな XML ドキュメントのストリーミング変換を実行します。For more information, see How to: Perform Streaming Transform of Large XML Documents.

適用対象

こちらもご覧ください