Processing XML with Perl | Michel Rodriguez |
Stream Processing | Filtering vs Extracting |
Tree processing
The other main model is the tree model: A whole document is parsed and loaded in memory as a tree. The tree can then be queried, updated and if needed output as XML.
The tree can either be a complex data structure (arrays of arrays of array... as in XML::Parser in Tree style or XML::Simple) or a "real tree" (as in XML::DOM, XML::XPath or XML::Twig).
Navigation in a "real" tree is often done using the child/sibling metaphor. Modifications is done using the cut/paste metaphor.
Pros
- complete re-ordering of the document is possible
- development is usually quicker
Cons
- the whole document is loaded in memory (and expanded into a tree, the expansion factor is usually around 10)
- before doing anything the document ihas to be loaded and the tree built, which can be quite slow
Usually development will be faster and the software more robust, as working with a tree is usually easier for programmers than dealing with a stream.
Stream Processing | Filtering vs Extracting |