Reputation: 15
I'm copying the text content of an element I need (which is an embedded xml doc) and creating the new doc from the text, as shown below for a file format delivered to me that I don't control. The issue is that occasionally i get large (3MB+) text values (xml files) delivered in this one element and the parser crashes (java heap space) - I think its because the value-of cant handle the text as a string in one. I'd like to ideally just do a copy-of or some sort of identity transform just to strip other elements, or copy without buffering it into a string. Am I right thinking this is the issue, and is there a way? (without adding more memory).
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:value-of select="root/toplevel/row/payload" />
</xsl:template>
</xsl:stylesheet>
<?xml version='1.0' ?>
<root>
<toplevel>
<row>
<payload>
<?xml version="1.0" encoding="UTF-8"?>
<documentProperties type="documentProperties">
<producedBy>
<ourName type="string">NAMEHERE</ourName>
<user>Someone</user>
</producedBy>
</documentProperties>
</payload>
<System>NotWanted</System>
</row>
</toplevel>NotWantedEither
</root>
Note the text in the sibling and parent elements at the end is not wanted and does sometimes get included with several attempts at copying I've tried. I only want whats in payload. This code works with this example but not when the text exceeds some size limit.
Output :
<?xml version="1.0" encoding="UTF-8"?>
<documentProperties type="documentProperties">
<producedBy>
<ourName type="string">NAMEHERE</ourName>
......
<.... in practice +3 MB more content in output and source element text here...>
.......
<user>Someone</user>
</producedBy>
</documentProperties>
Upvotes: 1
Views: 224
Reputation: 15
Didn't find a desired XSLT solution and needed a working process fairly quickly. Adding more memory solved this for me. Increased heap space Xmx to 10G as a workaround for the odd time this happens.
Upvotes: 0