XDocument.Save (TextWriter, SaveOptions) serializes this XDocument to a TextWriter with option : Load Save « XML LINQ « C# / C Sharp






XDocument.Save (TextWriter, SaveOptions) serializes this XDocument to a TextWriter with option

 
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Xml.Linq;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
public class MainClass
{
    public static void Main()
    {
        XDocument doc = new XDocument(
            new XElement("Root",
                new XElement("Child", "content")
            )
        );
        StringBuilder sb1 = new StringBuilder();
        using (StringWriter sr1 = new StringWriter(sb1))
        {
            doc.Save(sr1, SaveOptions.None);
            Console.WriteLine(sb1.ToString());
        }

        StringBuilder sb2 = new StringBuilder();
        using (StringWriter sr2 = new StringWriter(sb2))
        {
            doc.Save(sr2, SaveOptions.DisableFormatting);
            Console.WriteLine(sb2.ToString());
        }
    }
}

   
  








Related examples in the same category

1.XElement.Load loads an XElement from a file.
2.XElement.Load(String, LoadOptions) loads an XElement from a file
3.XElement.Load (TextReader) loads an XElement from a TextReader.
4.XElement.Load Method (TextReader, LoadOptions) loads an XElement from a TextReader
5.XElement.Load (XmlReader) loads an XElement from an XmlReader.
6.XElement.Save serializes this element to a file.
7.XElement.Save serializes this element to a file, optionally disabling formatting.
8.XElement.Save (TextWriter) serializes this element to a TextWriter.
9.XElement.Save (TextWriter, SaveOptions) serializes this element to a TextWriter
10.XElement.Save (XmlWriter) serializes this element to an XmlWriter.
11.XDocument.Load loads a XDocument from a file.
12.XDocument.Load(String, LoadOptions) loads an XDocument from a file with option
13.XDocument.Load (TextReader) creates a new XDocument from a TextReader.
14.XDocument.Load (TextReader, LoadOptions) loads an XDocument from a TextReader with option
15.XDocument.Load (XmlReader) loads an XDocument from an XmlReader.
16.XDocument.Load(XmlReader, LoadOptions) loads an XElement from an XmlReader with option
17.XDocument.Parse(String, LoadOptions) parse a string to create a new XDocument with option
18.XDocument.Save (String) serializes this XDocument to a file, overwriting an existing file, if it exists.
19.XDocument.Save (String, SaveOptions) serializes this XDocument to a file with option
20.XDocument.Save (TextWriter) serializes this XDocument to a TextWriter.
21.XDocument.Save Method (XmlWriter) serializes this XDocument to an XmlWriter.
22.XDocument.Parse (String) parses a string to create a new XDocument.