Creating a very large XML file with Linq-to-XML and Linq-to-SQL

I am trying to dump for XML a very large database (many gigabytes). I am using Linq-to-SQL to retrieve data from a database and Linq-to-XML to generate XML. I use XStreamingElementto keep memory low. However, the job still allocates all available memory before flipping over without writing any XML. The structure is as follows:

var foo =
    new XStreamingElement("contracts",
       <LinqtoSQL which fetches data>.Select(d =>
    new XElement("contract",
        ... generate attributes etc...
using (StreamWriter sw = new StreamWriter("contracts.xml"))
{
    using (XmlWriter xw = XmlWriter.Create(sw))
    {
        foo.WriteTo(xw);
    }
}

I also tried saving with:

foo.Save("contracts.xml", SaveOptions.DisableFormatting);

... to no avail.

Any clues?

+3
source share
3 answers

, "" , 10 000 XML. .

, - , XStreamingElement.

0

? XStreamingElement, , , XmlWriter ? , .

xml . ? ? , xml , XmlReader ( , XmlWriter).

, ... , , , .

+1

, : .: -)

XML , .

"" , - .

0

Source: https://habr.com/ru/post/1722265/


All Articles