[jdom-interest] Protected methods to make private
Bradley S. Huffman
hip at csa.cs.okstate.edu
Wed Jul 2 08:55:35 PDT 2003
Laurent Bihanic writes:
> Bradley S. Huffman wrote:
>
> OK for delaying the creation of the document. The getDocument method in
> JDOMResult is just a convenience method that tries to create a document from
> the XSLT result and returns null if it can't. It's usage is discouraged unless
> you're 100% sure the XSLT stylesheet actually produces a document.
>
> As for getResult, FragmentHandler does not have the problem of deciding
> whether to return a Document or a list of nodes as the result of an XSLT
> transform is always a list of nodes. Thus getResult never returns any
> document: The returned list can only contain Element, Comment, Text and PI
> nodes. With your new WIP SAXHandler, it may also contain a DocType node.
So what should SAXHandler do? The following
public Document getDocument() {
// Try creating a new document with the content in result list.
Document document = null;
try {
document = factory.document(new Element("bogus"));
document.setContent(result);
if (locator != null) {
document.setBaseURI(locator.getSystemId());
}
}
catch(RuntimeException exception) {
// Ignore
}
return document;
}
public List getResult() {
flushCharacters();
return result;
}
> Document content differs from element content in that it allows a DocType
> node, only one element node and no text node. But that one element node is
> just a regular element.
> Replacing the root element by a set of lists (children, attributes,
> namespaces, etc.) will not save any memory, IMHO, but the prefix resultion fo
> r
> the namespaces in scope will get a little bit tricky.
I just want to buffer root's content in a large buffer and delay doing any
addContent/setContent on the root element until root's corresponding
endElement. The idea being to avoid as much array reallocation as possible.
A initial array size of 5, while fine for most elements, is probably to small
for the root element in medium to large documents and the element most likely
to have to resize it's content array multiple times. Actually I suspect it
really isn't going to make that much difference, but still like to try just
to see what happens :)
Brad
More information about the jdom-interest
mailing list