#!perl -w use strict; use XML::LibXML; use Data::Dumper qw(Dumper); my $parser = XML::LibXML->new; my $doc = $parser->load_xml(string => <<'XML') or die; Madness 150 Maggie Rosie XML my $root = $doc->documentElement(); my $value = $root->nodeName; sub buildtree { my $node = shift; if (! ref $node) { print "Not a reference: '$node'\n"; return }; foreach my $child ( $node->getChildnodes ) { if( $child->nodeType eq &XML_ELEMENT_NODE ) { my $name; my $text; my $boolean; my $value; my $node; my @att; my $name = $child->nodeName; my $node = $child->nodeType; my $text = $child->textContent($name); my @att = map { sprintf "%s -> %s", $_->name, $_->value } $child->attributes(); my $has_children = $child->hasChildNodes(); print "Name:$name\n"; print "Text:$text\n"; print "Attributes:@att\n"; print "Has Child:$child\n"; } buildtree( $child ); } } buildtree($root);