Nevinitsin Yury > XML-Bare-0.271 > XML::Bare

Download:
XML-Bare-0.271.tar.gz

Dependencies

Annotate this POD (9)

Related Modules

XML::LibXML
XML::Simple
XML::Parser
more...
By perlmonks.org

CPAN RT

New  2
Open  1
View/Report Bugs
Module Version: 0.271   Source   Latest Release: XML-Bare-0.53

NAME ^

XML::Bare - Minimal XML parser implemented via a C state engine

VERSION ^

0.271 including simple-like tree building

SYNOPSIS ^

  use XML::Bare;
  
  my $xml = new XML::Bare( text => '<xml><name>Bob</name></xml>', forcearray => [qw/tag1 tag2/] );
  
  # Parse the xml into a hash tree
  my $root = $xml->parse();
  
  # Parse the xml into a L<XML::Simple>-like hash tree using forcearray option from C<new> method.
  my $simple_root = $xml->simple();
  
  # Print the content of the name node
  print $root->{xml}->{name}->{value};
  print $simple_root->{xml}->{name};
  
  # Load xml from a file ( assume same contents as first example )
  my $xml2 = new XML::Bare( file => 'test.xml' );
  
  my $root2 = $xml2->parse();
  
  $root2->{xml}->{name}->{value} = 'Tim';
  
  # Save the changes back to the file
  $xml2->save();  

DESCRIPTION ^

This module is a 'Bare' XML parser. It is implemented in C++. The parser itself is a simple state engine that is less than 500 lines of C++. The parser builds a C++ class tree from input text. That C++ class tree is converted to a Perl hash by a Perl function that makes basic calls back to the C++ to go through the nodes sequentially.

Supported XML

To demonstrate what sort of XML is supported, consider the following examples. Each of the PERL statements evaluates to true.

Parsed Hash Structure

The hash structure returned from XML parsing is created in a specific format. Besides as described above, the structure contains some additional nodes in order to preserve information that will allow that structure to be correctly converted back to XML.

Nodes may contain the following 2 additional subnodes (not $simple_root):

Parsing Limitations / Features

Module Functions

Performance

In comparison to other available perl xml parsers that create trees, XML::Bare is extremely fast. In order to measure the performance of loading and parsing compared to the alternatives, a test script has been created and is included with the distribution as 'test.pl'.

The test script can compare the speed of XML::Bare against the following alternatives:

To run the comparison, you must provide a number, 1-12, as a paramter to the script in order to choose which module to compare against. The script works this way because some of the modules have parts used by the other modules, which hides the loading time for the module tested later...

The script measures the milliseconds of loading and parsing, and compares the time against the time of XML::Bare. So a 7 means it takes 7 times as long as XML::Bare.

Here is a combined table of the script run against each alternative using the included test.xml:

  -Module-              load     parse    total
  XML::Bare             1        1        1
  XML::Parser::EasyTree 5.6811   29.2881  8.5366
  XML::Handler::Trees   7.8083   30.1434  10.503
  XML::Twig             31.0709  60.7735  34.5892
  XML::LibXML (no tree) 13.1591  1.8211   11.7857
  XML::Smart            6.9198   93.2242  17.1124
  XML::Simple           3.4242   207.0007 29.5704
  XML::SAX::Simple      9.82     191.0584 31.1326
  XML::Trivial          5.8321   7.009    6.3731
  XML::TreePP           2.5766   35.0588  6.4429
  XML::XPath::XMLParser 12.4321  41.0182  16.651
  XML::DOM::Lite        16.3544  14.8667  16.1905
  TinyXML                                 4.2033

Here is a combined table of the script run against each alternative using the included feed2.xml:

  -Module-              load     parse    total
  XML::Bare             1        1        1
  XML::Parser::EasyTree 5.442    23.234   10.0313
  XML::Handler::Trees   5.9811   20.5755  9.6939
  XML::Twig             32.0006  44.811   35.3799
  XML::LibXML (no tree) 13.5665  1.2518   10.0492
  XML::Smart            6.8234   42.8422  16.2711
  XML::Simple           3.9487   111.1732 31.6937
  XML::SAX::Simple      10.1525  90.7282  32.7888
  XML::Trivial          5.7941   28.5549  11.7381
  XML::TreePP           2.8155   4.5963   3.9556
  XML::XPath::XMLParser 11.9291  63.184   26.5266
  XML::DOM::Lite        17.1702  13.8642  16.286
  TinyXML                                 6.5016

These results show that XML::Bare is, at least on the test machine, ~3-30 times faster loading and ~10-150 times faster parsing than any of the alternative tree parsers.

The following are shown as well: - XML::Bare can parse XML and create a hash tree in less time than it takes LibXML just to parse. - XML::Bare can parse XML and create a hash tree in 1/4 the time it takes TinyXML just to parse

Note that TinyXML is not a perl module and is timed by a dummy program that just uses the library to load and parse the example files.

LICENSE ^

  Copyright (C) 2007 David Helkowski
  
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License as
  published by the Free Software Foundation; either version 2 of the
  License, or (at your option) any later version.  You may also can
  redistribute it and/or modify it under the terms of the Perl
  Artistic License.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
syntax highlighting: