Nick Kostyria
and 1 contributors

NAME

XML::Perl - XML producer from humane perl data, parser to base perl data and simple XPath

SYNOPSIS

  use XML::Perl;
  print perl2xml($data);
  print xmlformat($xml);
  my $t = xml2perlbase($xml);
  print perlbase2xml($t);
  print xpath($t, $xpath);

DESCRIPTION

XML::Perl is:

 - XML producer from humane perl data;
 - XML formater;
 - XML parser to base perl data;
 - XML producer from base perl data;
 - Simple XPath.

perl2xml

XML producer from humane perl data.

 my $xml = perl2xml($data);
 my $xml = perl2xml($data, 0, "\t", "\n");

 Perl (humane data)                    XML
 ----------------------------------------------------------
 {name => value}                      <name>value</name>
 ..........................................................
 {name => { a => b, c => d } }        <name>
                                          <a>b</a>
                                          <c>d</c>
                                      </name>
 ..........................................................
 {name => { '@a' => b, c => d } }     <name a="b">
                                          <c>d</c>
                                      </name>
 ..........................................................
 {name => { '@a' => b, '' => v } }    <name a="b">v</name>
 ..........................................................
 {name => { '@a' => b } }             <name a="b" />
 ..........................................................
 {name => [v1, v2, v2]}               <name>v1</name>
                                      <name>v2</name>
                                      <name>v3</name>
 ..........................................................
 {name => [                           <name a="b">v1</name>
     { '@a' => b, '' => v1 },         <name>v2</name>
     v2,                              <name>v3</name>
     v3,
     ] }
 ..........................................................

xmlformat

XML formater.

 print xmlformat($xml);

xml2perlbase

XML parser to base perl data.

 my $t = xml2perlbase($xml);

Base perl data:

 {
        name => [
                { a => b, '' => v },
                {}
        ],
        ...
 }

where: v - hash or scalar. Atention, a - is attribute.

perlbase2xml

XML producer from base perl data.

 my $xml = perlbase2xml($t);
 my $xml = perlbase2xml($t, 0, "\t", "\n");

xpath

Simple XPath

Examples:

 xpath($t, '/a/b');
 xpath($t, '/a[2]/b');
 xpath($t, '/a/b[2]/@a');
 xpath($t, 'a/b');

AUTHOR

Nick Kostirya

COPYRIGHT AND LICENSE

Copyright (C) 2011 by Nick Kostirya

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.