Hi:
I'm trying to read large XML documents using the Context.getXMLParser() from where I expect to retrieve a JDOM parser for navegating through the XML tree. Unfortunately, I get a "Java heap space" error which finishes, abruptly, the execution of the script, probably due to the size of those documents.
Known some disadvantages of using DOM-like APIs for reading XML documents (like a proved high memory consumption), I'm figuring how to achieve my goal with other alternatives, like using a (Java) SAX-compliant XML Parser...
Did anyone do this before? Any suggestions?
All the help you can provide me will be highly appreciated.
Best regards,
Ricardo
Jens Heylmann on
Hi Ricardo,
it is possible to use an alternative XML parser like SAX. In a report script you can call Java.Packages. To load a XML file for example:
this.init2 = function() { try { var locale = Packages.com.idsscheer.utils.locale.ALocaleConverter.getLocale( Context.getSelectedLanguage() ).getLanguage(); var filedata = Context.getFile("filename.xml", Constants.LOCATION_COMMON_FILES); var factory = new Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance(); factory.setValidating(true); var builder = factory.newDocumentBuilder(); propertiesfile = builder.parse( new java.io.ByteArrayInputStream( new java.lang.String( filedata ).getBytes("UTF-8") ) ); } catch(e) { //do nothing } }Regards,
Jens