XDocument.WriteTo(XmlWriter) Método

Definição

Escreva este documento em um 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)

Parâmetros

writer
XmlWriter

Um XmlWriter no qual esse método será gravado.

Exemplos

O exemplo a seguir mostra como gravar um XDocument em um XmlWriter. Observe que o exemplo não gravou uma declaração XML.

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

Este exemplo produz a seguinte saída:

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

Aplica-se a

Confira também