XML::LibXML
Low level library, Perl binding to libxml2 supports the standard XML processing mode called Document Object Mode (DOM).
examples/xml/libxml.pl
#!/usr/bin/perl use strict; use warnings; use XML::LibXML; my $parser = XML::LibXML->new; my $doc = $parser->parse_file('examples/data.xml'); print $doc; process_node( $doc->getDocumentElement, 0); sub process_node { my ($node, $depth) = @_; print "$node\n"; return unless( $node->nodeType eq &XML_ELEMENT_NODE ); print " " x $depth, $node->nodeName, "\n"; foreach my $child ( $node->getChildnodes ) { process_node( $child, $depth+1 ); } }
Other Node types (taken from the source code) XML_COMMENT_NODE XML_TEXT_NODE XML_CDATA_SECTION_NODE XML_ELEMENT_NODE XML_ENTITY_REF_NODE XML_DOCUMENT_NODE XML_HTML_DOCUMENT_NODE XML_DOCUMENT_FRAG_NODE XML_PI_NODE XML_XINCLUDE_START XML_XINCLUDE_END XML_DTD_NODE