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

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

Written By
Web Webster
Web Webster
Jul 9, 2000

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

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.