与C#大型XML文件的XSLT转换 [英] XSLT transformation on Large XML files with C#

查看:307
本文介绍了与C#大型XML文件的XSLT转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些非常大的XML文件(800 MB到1.5 GB)。我需要在适用XSLT。我能读它XmlTextReader的。当我申请XSLT转换,得到SystemOutOfMemory异常

I have some very large XML files (800 MB to 1.5 GB). I need to apply XSLT on that. I am able to read it XMLTextReader. When i applied XSLT transformation, get SystemOutOfMemory Exception.

我的代码看起来像;

static void Main(string[] args)
{
    XDocument newTree = new XDocument();
    XmlTextReader oReader = new XmlTextReader(@"C:\Projects\myxml.xml");


    using (XmlWriter writer = newTree.CreateWriter())
    {
        XslCompiledTransform oTransform = new XslCompiledTransform();
        oTransform.Load(@"C:\Projects\myXSLT.xsl");
        oTransform.Transform(oReader, writer);
    }
    Console.WriteLine(newTree);
}

在此先感谢。这是非常紧迫的。如果我没有得到任何的解决方案,我需要将XML分割成更小的XML,并做转换。

Thanks in advance. It is very urgent. If I don't get any solution, I need to split XML into smaller XML and do transformation.

推荐答案

XSLT使用XPath和这要求在整个XML文档中存储器被维持。 因此,内存不足的问题是通过定义

XSLT uses XPath and this requires that the whole XML document be maintained in memory. Thus the problem of insufficient memory is by definition.

有笑着规则近似多少内存需要,其中一人说: 5 *文字大小

There are simle rules to approximate how much memory is needed and one of them says 5 * text-size.

所以,对于一个典型1.5GB XML文件8GB的内存就足够了。

So, for a "typical 1.5GB XML file" 8GB RAM may be sufficient.

无论是拆分文档分成较小的部分或等待 XSLT 2.1 ,它定义了专门的流媒体指令。在此期间人们可以使用撒克逊,它实现了流媒体和64GB的文档的成功处理扩展已报告在Twitter上的最新版本(商业)版本。

Either split the document into smaller parts or wait for an implementation of XSLT 2.1, which defines special streaming instructions. In the meantime one may use the latest (commercial) version of Saxon, which implements extensions for streaming and successful processing of 64GB document has been reported on twitter.

这篇关于与C#大型XML文件的XSLT转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆