XDocument.WriteTo Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Write this document to an XmlWriter.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Parameters
- writer
- Type: System.Xml.XmlWriter
An XmlWriter into which this method will write.
The following example shows how to write an XDocument to an XmlWriter. Note that the example did not write an XML declaration.
StringBuilder output = new StringBuilder(); 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); } output.Append(sb.ToString() + Environment.NewLine); OutputTextBlock.Text = output.ToString();
Show: