XML::Rules

XML::Rules is a Perl module that can parse XML & process tags by rules starting from leaves.
Download

XML::Rules Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Jan Krynicky
  • Publisher web site:
  • http://search.cpan.org/~jenda/

XML::Rules Tags


XML::Rules Description

XML::Rules is a Perl module that can parse XML & process tags by rules starting from leaves. XML::Rules is a Perl module that can parse XML & process tags by rules starting from leaves.SYNOPSIS use XML::Rules; $xml = < < '*END*' < doc > < person > < fname >...< /fname > < lname >...< /lname > < email >...< /email > < address > < street >...< /street > < city >...< /city > < country >...< /country > < bogus >...< /bogus > < /address > < phones > < phone type="home" >123-456-7890< /phone > < phone type="office" >663-486-7890< /phone > < phone type="fax" >663-486-7000< /phone > < /phones > < /person > < person > < fname >...< /fname > < lname >...< /lname > < email >...< /email > < address > < street >...< /street > < city >...< /city > < country >...< /country > < bogus >...< /bogus > < /address > < phones > < phone type="office" >663-486-7891< /phone > < /phones > < /person > < /doc > *END* @rules = ( _default = > sub {$_ = > $_- >{_content}}, # by default I'm only interested in the content of the tag, not the attributes bogus = > undef, # let's ignore this tag and all inner ones as well address = > sub {address = > "$_- >{street}, $_- >{city} ($_- >{country})"}, # merge the address into a single string phone = > sub {$_- >{type} = > $_- >{content}}, # let's use the "type" attribute as the key and the content as the value phones = > sub {delete $_- >{_content}; %{$_}}, # remove the text content and pass along the type = > content from the child nodes person = > sub { # lets print the values, all the data is readily available in the attributes print "$_- >{lname}, $_- >{fname} < $_- >{email} >n"; print "Home phone: $_- >{home}n" if $_- >{home}; print "Office phone: $_- >{office}n" if $_- >{office}; print "Fax: $_- >{fax}n" if $_- >{fax}; print "$_- >{address}nn"; return; # the < person > tag is processed, no need to remember what it contained }, ); $parser = XML::Rules- >new(rules = > @rules); $parser- >parse( $xml); Requirements: · Perl


XML::Rules Related Software