On 09 Mar 2008, at 15:17, Asankha C. Perera wrote:

The solution for the first problem is actually surprisingly simple. The correct behavior can be achieved by replacing the code by the following instructions:

OMNode node = firstChild.getFirstOMChild();
while (node != null) {
   if (node instanceof OMText) {
       os.write(((OMText)node).getText().getBytes());
   }
   node = node.getNextOMSibling();
}

I checked that for an OMSourcesElementImpl node backed by a TextFileDataSource object, getFirstOMChild and getNextOMSibling will read a single chunk of text from the WrappedTextNodeStreamReader constructed by TextFileDataSource. Therefore the replacement code will handle large temporary files with the same efficiency as the original code.
I am to blame for the original code :-) But your suggestion looks cool so +1 to go ahead..


Actually I was wrong. In the code I proposed, the produced OMText nodes will be added to the tree and therefore the entire file will still be loaded into memory. Probably the best solution is as follows:

if (firstChild instanceof OMSourcedElementImpl) {
    XMLStreamReader reader = firstChild.getXMLStreamReader();
    while (reader.hasNext()) {
        if (reader.next() == XMLStreamReader.CHARACTERS) {
            os.write(reader.getText().getBytes());
        }
    }
} else {
    os.write(firstChild.getText().getBytes());
}

Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to