So I am a little new to XML::Parser but I have read the docs and PODs and know that this module has what I need but I am a little stuck on the implementation.
I have this XML:
and I have this perl script:<?xml version='1.0' encoding='UTF-8'?> <list name="name list"> <person> <firstname>Paul</firstname> <lastname>Rutter</lastname> <age>24</age> </person> <person> <firstname>Ruth</firstname> <lastname>Brewster</lastname> <age>22</age> </person> <person> <firstname>Cas</firstname> <lastname>Creer</lastname> <age>23</age> </person> </list>
which prints the contents of the xml to the screen. However what I really want to do is Parse through the file taking out each firstname and putting them in an array. At the very least I would quite like to just know how to 'get at' to a node.#!/usr/bin/perl use XML::Parser; use Data::Dumper; use strict; use warnings; $parser = new XML::Parser( Style => 'Tree' ); my $tree = $parser->parsefile( 'testxml.xml' ); print Dumper( $tree );
The $tree - is it an array? a scalar? a variable? little confused there you see. If it is a scalar, how do I get access to it?
Thanks in advance
In reply to Trees in XML by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |