![]() |
![]()
| ![]() |
![]()
NAMEXML::Hash::LX - Convert hash to xml and xml to hash using LibXML SYNOPSISuse XML::Hash::LX; my $hash = xml2hash $xmlstring, attr => '.', text => '~'; my $hash = xml2hash $xmldoc; my $xmlstr = hash2html $hash, attr => '+', text => '#text'; my $xmldoc = hash2html $hash, doc => 1, attr => '+'; # Usage with XML::LibXML my $doc = XML::LibXML->new->parse_string($xml); my $xp = XML::LibXML::XPathContext->new($doc); $xp->registerNs('rss', 'http://purl.org/rss/1.0/'); # then process xpath for ($xp->findnodes('//rss:item')) { # and convert to hash concrete nodes my $item = xml2hash($_); print Dumper+$item } DESCRIPTIONThis module is a companion for "XML::LibXML". It operates with LibXML objects, could return or accept LibXML objects, and may be used for easy data transformations It is faster in parsing then XML::Simple, XML::Hash, XML::Twig and of course much slower than XML::Bare ;) It is faster in composing than XML::Hash, but slower than XML::Simple Parse benchmark: Rate Simple Hash Twig Hash::LX Bare Simple 11.3/s -- -2% -16% -44% -97% Hash 11.6/s 2% -- -14% -43% -97% Twig 13.5/s 19% 16% -- -34% -96% Hash::LX 20.3/s 79% 75% 51% -- -95% Bare 370/s 3162% 3088% 2650% 1721% -- Compose benchmark: Rate Hash Hash::LX Simple Hash 49.2/s -- -18% -40% Hash::LX 60.1/s 22% -- -26% Simple 81.5/s 66% 36% -- Benchmark was done on <http://search.cpan.org/uploads.rdf> EXPORT"xml2hash" and "hash2xml" are exported by default :injectInject toHash method in the namespace of XML::LibXML::Node and allow to call it on any subclass of XML::LibXML::Node directly By default is disabled use XML::Hash::LX ':inject'; my $doc = XML::LibXML->new->parse_string($xml); my $hash = $doc->toHash(%opts); FUNCTIONSxml2hash $xml, [ OPTIONS ]XML could be XML::LibXML::Document, XML::LibXML::DocumentPart or string hash2xml $hash, [ doc => 1, ] [ OPTIONS ]Id "doc" option is true, then returned value is XML::LibXML::Document, not string OPTIONSEvery option could be passed as arguments to function or set as global variable in "XML::Hash::LX" namespace %XML::Hash::LX::X2HOptions respecting convertations from xml to hash
$XML::Hash::LX::X2A [ = 0 ]Global array casing Ignored when "X2H{order}" in effect As option should be passed as xml2hash $xml, array => 1; Effect: # $X2A = 0 <node><sub/></node> => { node => { sub => '' } } # $X2A = 1 <node><sub/></node> => { node => [ { sub => [ '' ] } ] } %XML::Hash::LX::X2ABy element array casing Ignored when "X2H{order}" in effect As option should be passed as xml2hash $xml, array => [ nodes list ]; Effect: # %X2A = () <node><sub/></node> => { node => { sub => '' } } # %X2A = ( sub => 1 ) <node><sub/></node> => { node => { sub => [ '' ] } } %XML::Hash::LX::H2XOptions respecting convertations from hash to xml
BUGSNone known SEE ALSO
AUTHORMons Anderson, "<mons at cpan.org>" LICENSECopyright 2009-2020 Mons Anderson, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|