Creating a DOM that is thread safe for read operations

My application is building a web page model from multiple XML sources. These sources are analyzed in memory as DOM objects with a regular Xerces parser. Unfortunately, Xerces DOM objects are not thread safe for read-only operations. I would like to be able to reuse the parsed DOM for reading. Does anyone know of another parser or simple streaming security for reading the DOM implementation that I use?

+5
source share
2 answers

Saxon provides DOM wrappers for its internal and immutable data structure.

// create Saxon IdentityTransformer
final Transformer transformer = new TransformerFactoryImpl().newTransformer();

// set up holder for the output
final TinyBuilder outputTarget = new TinyBuilder(
    new PipelineConfiguration(new Configuration()));

// transform into Saxon immutable TinyTree
transformer.transform(xml, outputTarget);

// extract the whole XML as TinyNode 
final TinyNodeImpl tinyNode = outputTarget.getTree().getNode(0);

// wrap TinyNode as DOM
final NodeOverNodeInfo nodeOverNodeInfo = DocumentOverNodeInfo.wrap(tinyNode);

// cast to DOM
final Document doc = (Document) nodeOverNodeInfo;

(verified using Saxon-on 9.5.1)

+4

.

Dom .

, . , (, , ).

, , ...

0

All Articles