<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">Laurent,<br><br>Commenting out those lines results in an exception:<br><br>Exception in thread "main" org.xml.sax.SAXException: Ill-formed XML document (multiple root elements detected)<br>&nbsp;&nbsp;&nbsp; at org.jdom.input.SAXHandler.getCurrentElement(SAXHandler.java:918)<br>&nbsp;&nbsp;&nbsp; at org.jdom.input.SAXHandler.startElement(SAXHandler.java:556)<br>&nbsp;&nbsp;&nbsp; at org.jdom.contrib.input.scanner.ElementScanner.startElement(ElementScanner.java:548)<br>&nbsp;&nbsp;&nbsp; at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)<br>&nbsp;&nbsp;&nbsp; at
 com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:330)<br>&nbsp;&nbsp;&nbsp; at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1693)<br>&nbsp;&nbsp;&nbsp; at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)<br>&nbsp;&nbsp;&nbsp; at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)<br>&nbsp;&nbsp;&nbsp; at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)<br>&nbsp;&nbsp;&nbsp; at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)<br>&nbsp;&nbsp;&nbsp; at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)<br>&nbsp;&nbsp;&nbsp; at
 org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333)<br>&nbsp;&nbsp;&nbsp; at org.jdom.contrib.input.scanner.ElementScanner.parse(ElementScanner.java:442)<br><br>It looks like that causes SaxHandler to add multiple root elements to the document.&nbsp; I tried tracking this down but had no luck finding the problem and don't have more time to dedicate to it.&nbsp; I think it has something to do with the isRoot flag in the SaxHandler not being reset.<br><br>-Brian<br><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: Laurent Bihanic &lt;laurent.bihanic@atosorigin.com&gt;<br>To: Brian Nahas &lt;briannahas@yahoo.com&gt;<br>Cc: jdom-interest@jdom.org<br>Sent: Tuesday, November 14, 2006 6:53:40 PM<br>Subject: Re: [jdom-interest] ElementScanner and Memory<br><br><div>Hi,<br><br>Yes, this looks like a bug.<br><br>ElementScanner relies on the EmptyDocument and EmptyDocumentFactory nested <br>classes to
 prevent any document to be built.<br>So, something has gone wrong here!<br><br>Comparing the current code (from CVS) and the original code (2002), I think <br>the problem may come from FragmentHandler which was imported from JDOMResult <br>as a replacement for the original ElementBuilder.<br><br>The following statement was imported:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Add a dummy root element to the being-built document as XSL<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// transformation can output node lists instead of well-formed<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// documents.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.pushElement(new Element("root", null, null));<br><br>It makes sense for JDOMResult (the comment explains why) but not here.<br><br>I suspect the root element it adds allows SAXHandler to attach the build <br>Elements hence causing the memory
 leak.<br><br>Could you remove these lines from FragmentHandler's constructor et verify this <br>fixes the problem ?<br><br>Laurent<br><br><br>Brian Nahas a écrit :<br>&gt; I have a 1.2 GB xml file I need to parse.&nbsp;&nbsp;Since it's nicely <br>&gt; partitioned, I planned on using ElementScanner from the contrib package <br>&gt; to only load one item at a time.&nbsp;&nbsp;Here's an equivalent schema:<br>&gt; <br>&gt; &lt;data&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;item&gt;...&lt;/item&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;item&gt;...&lt;/item&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;item&gt;...&lt;/item&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; ...<br>&gt; &lt;/data&gt;<br>&gt; <br>&gt; The path for I'm using for my listener is "/data/item".<br>&gt; <br>&gt; I assumed any previous items would be released by the parser upon <br>&gt; completion.&nbsp;&nbsp;ElementScanner was very simple to set up to handle this, <br>&gt; however I ran into an OutOfMemory error on my first
 try.&nbsp;&nbsp;I was a little <br>&gt; confused as I thought ElementScanner was specifically designed to <br>&gt; prevent this.&nbsp;&nbsp;Upon investigation, I found that the SAXHandler used by <br>&gt; the ElementScanner was holding onto the previous items after I was done <br>&gt; with them.&nbsp;&nbsp;It adds them to the default root element that <br>&gt; FragmentHandler creates and nothing removes them after the listeners are <br>&gt; called.&nbsp;&nbsp;This seems to be in direct conflict with this message I found <br>&gt; which states that ElementScanner doesn't build a document (this message <br>&gt; is fairly old though):<br>&gt; <br>&gt; <a target="_blank" href="http://www.servlets.com/archive/servlet/ReadMsg?msgId=350607&amp;listName=jdom-interest">http://www.servlets.com/archive/servlet/ReadMsg?msgId=350607&amp;listName=jdom-interest</a> <br>&gt; &lt;<a target="_blank"
 href="http://www.servlets.com/archive/servlet/ReadMsg?msgId=350607&amp;listName=jdom-interest">http://www.servlets.com/archive/servlet/ReadMsg?msgId=350607&amp;listName=jdom-interest</a>&gt;<br>&gt; <br>&gt; I worked around this by explicitly detaching the element in my listener <br>&gt; when I was done with it, but since it seems like this would be a common <br>&gt; pattern and subtle trap, so I thought I'd ask and see if I was missing <br>&gt; some setting or improperly using ElementScanner.&nbsp;&nbsp;There's a namespace <br>&gt; declared on the data element so I don't know if that has something to do <br>&gt; with it.<br>&gt; <br>&gt; Thanks,<br>&gt; -Brian<br></div></div><br></div></div></body></html>