XDocument.WriteTo(XmlWriter) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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)
Parameters
Examples
The following example shows how to write an XDocument to an XmlWriter. 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>
Applies to
See also
Совместная работа с нами на GitHub
Источник этого содержимого можно найти на GitHub, где также можно создавать и просматривать проблемы и запросы на вытягивание. Дополнительные сведения см. в нашем руководстве для участников.