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.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    XML::Reader 0.49

    Download button

    No screenshots available
    Downloads: 153  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Klaus Eichner | More programs
    Perl Artistic License / FREE
    September 23rd, 2012, 07:47 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    XML::Reader description

    Reading XML and providing path information based on a pull-parser

    XML::Reader is a Perl module that provides a simple and easy to use interface for sequentially parsing XML files (so called "pull-mode" parsing) and at the same time keeps track of the complete XML-path.

    It was developped as a wrapper on top of XML::Parser or XML::Parsepp (while, at the same time, some basic functions have been copied from XML::TokeParser). all modules, XML::Parser, XML::Parsepp and XML::TokeParser allow pull-mode parsing, but do not keep track of the complete XML-Path. Also, the interfaces to XML::Parser, XML::Parsepp and XML::TokeParser require you to distinguish between start-tags, end-tags and text on seperate lines, which, in my view, complicates the interface (although, XML::Reader allows option {filter => 4, mode => 'pyx'} which emulates start-tags, end-tags and text on separate lines, if that's what you want).

    There is also XML::TiePYX, which lets you pull-mode parse XML-Files (see http://www.xml.com/pub/a/2000/03/15/feature/index.html for an introduction to PYX). But still, with XML::TiePYX you need to account for start-tags, end-tags and text, and it does not provide the full XML-path.

    By contrast, XML::Reader translates start-tags, end-tags and text into XPath-like expressions. So you don't need to worry about tags, you just get a path and a value, and that's it. (However, should you wish to operate XML::Reader in a PYX compatible mode, there is option {filter => 4, mode => 'pyx'}, as mentioned above, which allows you to parse XML in that way).

    SYNOPSIS

     use XML::Reader;

     my $text = q{< init >n < ?test pi? > t< page node="400" >m < !-- remark -- > r< /page >< /init >};

     my $rdr = XML::Reader->new(\$text);
     while ($rdr->iterate) {
     printf "Path: %-19s, Value: %s\n", $rdr->path, $rdr->value;
     }


    This program produces the following output:

     Path: /init , Value: n t
     Path: /init/page/@node , Value: 400
     Path: /init/page , Value: m r
     Path: /init , Value:


    You can also wrap the call to XML::Reader->new(...) into an eval {...} to check if it succeeded, as follows:

     my $rdr = eval{ XML::Reader->new('test.xml') }
     or warn "Can't XML::Reader->new() because $@";

     if ($rdr) {
     # ... do something with $rdr ...
     }
     else {
     # ... do some error handling ...
     }



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    XML reader | Perl module | Perl | XML | reader

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

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