Nov 1999
Revision History | ||
---|---|---|
Revision 0.09 | 15 Nov 1999 | |
--Add support to attributes | ||
Revision 0.06 | 4 Nov 1999 | |
--Change to an object class | ||
Revision 0.04 | 20 Oct 1999 | |
--The first version that's submitted to CPAN. |
XML::Node is for those who use Perl to process XML files. XML::Node is built on top of XML::Parser and provides a simplified programming interface. XML::Node users can register callback sub-routines or variables to specific type of XML nodes. The values of the specified XML nodes are automatically copied to the corresponding variables. When specified XML tags are found, registered callback sub-routines are called. XML::Node is a shortcut to XML::Parser if you don't care much about details of XML files.
Here is an example. This XML file contains order information:
Example 1. orders.xml
<Orders> <Order> <Item>A Book</Item> <Quantity>1</Quantity> <TagsThatIDontCare>Something</TagsThatIDontCare> </Order> <TagsThatIDontCare>Blah Blah</TagsThatIDontCare> </Orders> |
Example perl. parse_orders.pl
use XML::Node; my $item = ""; my $quantity = ""; $p = XML::Node->new(); $p->register(">Orders>Order>Item","char" => \$item); $p->register(">Orders>Order>Quantity","char" => \$quantity); $p->register(">Orders>Order","end" => \&handle_order_end); print "Processing file [orders.xml]...\n"; $p->parsefile("orders.xml"); sub handle_order_end { print "Found order -- Item: [$item] Quantity: [$quantity]\n"; $item = ""; $quantity = ""; } |
The XML::Node module can be found at http://belmont-shores.ics.uci.edu/pub, ftp://belmont-shores.ics.uci.edu/pub, or Perl CPAN.
Please submit any related bugs, issues, suggestions, or comments to http://belmont-shores.ics.uci.edu/bugzilla.