XML::Descent

XML::Descent is a Perl module for recursive descent XML parsing.
Download

XML::Descent Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Andy Armstrong
  • Publisher web site:
  • http://search.cpan.org/~andya/

XML::Descent Tags


XML::Descent Description

XML::Descent is a Perl module for recursive descent XML parsing. XML::Descent is a Perl module for recursive descent XML parsing.SYNOPSIS use XML::Descent; # Create parser my $p = XML::Descent->new({ Input => $xml }); # Setup handlers $p->on(folder => sub { my ($elem, $attr) = @_; $p->on(url => sub { my ($elem, $attr) = @_; my $link = { name => $attr->{name}, url => $p->text() }; $p->stash(link => $link); }); my $folder = $p->walk(); $folder->{name} = $attr->{name}; $p->stash(folder => $folder); }); # Parse my $res = $p->walk();The conventional models for parsing XML are either DOM (a data structure representing the entire document tree is created) or SAX (callbacks are issued for each element in the XML).XML grammar is recursive - so it's nice to be able to write recursive parsers for it. XML::Descent allows such parsers to be created.Typically a new XML::Descent is created and handlers are defined for elements we're interested in my $p = XML::Descent->new({ Input => $xml }); $p->on(link => sub { my ($elem, $attr) = @_; print "Found link: ", $attr->{url}, "n"; $p->walk(); # recurse }); $p->walk(); # parseA handler provides a convenient lexical scope that lasts until the closing tag of the element that triggered the handler is reached.When called at the top level the parsing methods walk(), text() and xml() parse the whole XML document. When called recursively within a handler they parse the portion of the document nested inside node that triggered the handler.New handlers may be defined within a handler and their scope will be limited to the XML inside the node that triggered the handler. Requirements: · Perl


XML::Descent Related Software