Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    YAX 0.03

    Download button

    No screenshots available
    Downloads: 273  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Richard Hundt | More programs
    Perl Artistic License / FREE
    November 15th, 2011, 02:54 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    YAX description

    Yet Another XML library

    YAX is a fast pure Perl XML library for easily parsing, querying, constructing and manipulating XML. Simple benchmarks have shown that it is substantially faster than XML::DOM::Parser which uses Expat internally (which is written in C), see "PERFORMANCE" for an explanation and related caveats.

    However, the main point of YAX is to remove the verbosity of the DOM API by using more perlish tricks such as operator overloading. For example, element nodes can behave as both array references and hash references. If dereferenced as an array reference, then a list of children is returned; as a hash reference, the attributes hash is returned. So the following show uses cases for this:

     my @good_books = grep { $_->{author} =~ /Asimov/ } @$elmt;

    You can also hang out of band data onto your elements:

     $elmt->{notes} = IO::File->new( './notes/asimov.txt' );

    without affecting serialization since attributes who's values are references are ignored during stringification.

    YAX nodes, of course, also provide methods for appending, replacing and removing children as well (note the following all operate on the children of $node):

     $node->replace( $new_child, $ref_child );
     $node->remove( $child );
     $node->append( $child );
     $node->insert( $new_child, $ref_child );


    SYNOPSIS

     use YAX::Parser;
     
     # DOM parse
     my $xdoc = YAX::Parser->parse( $xstr );
     my $xdoc = YAX::Parser->parse_file( '/some/file.xml' );
     
     # stream parse
     YAX::Parser->stream( $xstr, $state,
     text => &parse_text,
     elmt => &parse_element_open,
     elcl => &parse_element_close,
     ... # see YAX::Parser
     );
     YAX::Parser->stream_file( '/some/file.xml', $state, %handlers );
     
     # access the document root
     my $root = $xdoc->root;
     
     # get an element by id
     my $elmt = $xdoc->get( 'foo' );
     
     # attribute access
     $elmt->{meaning} = 42;
     
     # loop over children
     for my $child ( @$elmt ) {
     ...
     }
     
     # query the DOM
     my $nlst = $elmt->query(q{..a.b.*.(@foo eq 'bar')[1 .. 2]});
     
     # declarative programmatic DOM construction
     use YAX::Builder;
     my $node = YAX::Builder->node(
     [ table => { border => 1 },
     [ tr =>
     [ td => { align => 'top' },
     [ a => { href => '/foo' }, "Click Me!" ]
     ]
     ]
     ]
     );
     
     # serialization
     my $xstr = $node->as_string;
     my $xstr = "$node"; # '""' is overloaded



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    XML library | Perl module | Perl | XML | library

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM