 |
 |
 |
Does anyone know the solution to the problem documented below? I was able to
produce this following the instructions.
--
Say I have the following source XML and XSLT (see below). No matter what
this XSLT does. It is just a sample to show a problem. the idea is that
XSLT transforms small XML into quite big XML. Now, I have a straightforward
C# (see below) code that does this transform and writes result into
XmlTextWriter.
(Oleg's NXSLT.EXE is also suitable).
Problem:
If source XML is bigger, say several MBs (please don't explain me that it
is not good to use XSLT for such documents), the sample transform should
produce a very big (add more calls to template b if necessary and <a />
elements
to source document) XML. While result is writtent to the writer I expect
that it will not consume much more memory that source document. (I even
tried to provide custom XmlWriter which runs GC each 1000 element outputed).
However, I get OutOfMemory exception.
So, I looked at heap and what I see. I have in memory one 0.5GB object.
It is System.String containing:
uri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaa...................(much
longer - 0.5 GB)
Samples below generate smaller string, but anyway it is many times
concantenated
namespaces declared in XSLT (except XSLT namespace).
This XSLT runs fine in MSXML4 producing output to SAXHandler interface.
Any ideas how to avoid this long string in memory?
Parts of memory dump:
=== DUMP ===
..load sos
!DumpHeap -type System.String
PDB symbol for mscorwks.dll not loaded
succeeded
Loaded Son of Strike data table version 5 from
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorwks.dll"
Address MT Size
00af117c 79c125c8 28
00af11f0 79c125c8 108
00af125c 79c125c8 20
...........[vbcol=seagreen]
00b3d524 79c125c8 76
00b3d570 79c125c8 76
00b3d5bc 79c125c8 84
total 1647 objects
Statistics:
MT Count TotalSize Class Name
79c125c8 1647 91732 System.String
Total 1647 objects
!DumpObj 00b3bf04
Name: System.String
MethodTable 0x79c125c8
EEClass 0x79c12914
Size 1044(0x414) bytes
mdToken: 0200000f (c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll)
String:
uri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaauri:aaaur
i:aaauri:aaauri:aaauri:aaauri:aaauri:aaa
FieldDesc*: 79c12978
MT Field Offset Type Attr Value Name
79c125c8 4000013 4 System.Int32 instance 513 m_arrayLength
79c125c8 4000014 8 System.Int32 instance 287 m_stringLength
79c125c8 4000015 c System.Char instance 75 m_firstChar
79c125c8 4000016 0 CLASS shared static Empty[vbcol=seagreen]
79c125c8 4000017 4 CLASS shared static WhitespaceChars[vbcol=seagreen]
======== XML ========
<xml>
<a /> <a /> <a /> <a /> <a /> <a /> <a /> <a /> <a /> <a />
<a /> <a /> <a /> <a /> <a /> <a /> <a /> <a /> <a /> <a />
<a /> <a /> <a /> <a /> <a /> <a /> <a /> <a /> <a /> <a />
<a /> <a /> <a /> <a /> <a /> <a /> <a /> <a /> <a /> <a />
</xml>
======== XSLT ========
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:a="uri:aaa"
version="1.0"[vbcol=seagreen]
>[/vbcol]
<xsl:output method="xml" encoding="utf-8" />
<xsl:template name="b">
<c />
</xsl:template>
<xsl:template match="a">
<xsl:call-template name="b" />
<xsl:call-template name="b" />
<xsl:call-template name="b" />
<xsl:call-template name="b" />
</xsl:template>
<xsl:template match="/xml">
<xml>
<xsl:apply-templates />
</xml>
</xsl:template>
</xsl:transform>
====== C# ===============
namespace some {
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
class App {
[STAThread] static void Main(string[] args) {
XslTransform transform = new XslTransform();
transform.Load(args[1]);
XPathDocument source = new XPathDocument(args[0]);
XmlTextWriter writer = new XmlTextWriter(args[2], Encoding.UTF8);
XsltArgumentList xslArgs = new XsltArgumentList();
transform.Transform(source, xslArgs, writer);
writer.Close();
}
}
}
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |