---

IBM developerWorks: Dare to script tree-based XML with Perl

Parsing an XML document into tree structures makes it
possible to operate on the tree structure of the data. Find out how
to use the functions for accessing and manipulating the document
tree, and follow a sample stock-trading application that uses Perl,
DOM, XML, and a database to evaluate trading rules.
(You can
apply the same techniques with other scripting languages, including
Tcl and Python.) This is the second installment on using scripting
languages to manipulate and transform XML documents.”

“My previous article discussed how to manipulate XML with
scripting languages, and Perl in particular. In the course of
parsing a file that way, handlers are called as each tag is
encountered. That provides a very efficient means of processing
XML, both in memory usage and processing time. However, certain
tasks are difficult to accomplish in the event-based methodology.
Imagine, for example, needing to move or rearrange certain segments
of the document or sorting items within the document. Because the
document is processed as a stream, we would first need to store the
components before sorting or rearranging them. A mechanism that
would store the components automatically would make such tasks
substantially easier.”

“XML documents are required to be well-balanced, making it easy
to store them as trees. Once you parse XML documents into tree
structures, you can then operate on the tree. This yields a great
deal of flexibility in dealing with the documents: you can access
the components of the document in random order, rearrange them, and
add or remove them. This is especially appropriate for applications
in which the flow of processing is based on external logic, as
opposed to the order and occurance of elements within the XML
document. Storing the document as a tree enables random access to
its data and structure, instead of having the processing governed
by when and where the tags and elements occur.”


Complete Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis