{
    "mode": "perldoc",
    "parameter": "XML::Hash::LX",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3AHash%3A%3ALX/json",
    "generated": "2026-06-12T22:53:38Z",
    "synopsis": "use XML::Hash::LX;\nmy $hash = xml2hash $xmlstring, attr => '.', text => '~';\nmy $hash = xml2hash $xmldoc;\nmy $xmlstr = hash2html $hash, attr => '+', text => '#text';\nmy $xmldoc = hash2html $hash, doc => 1, attr => '+';\n# Usage with XML::LibXML\nmy $doc = XML::LibXML->new->parsestring($xml);\nmy $xp  = XML::LibXML::XPathContext->new($doc);\n$xp->registerNs('rss', 'http://purl.org/rss/1.0/');\n# then process xpath\nfor ($xp->findnodes('//rss:item')) {\n# and convert to hash concrete nodes\nmy $item = xml2hash($);\nprint Dumper+$item\n}",
    "sections": {
        "NAME": {
            "content": "XML::Hash::LX - Convert hash to xml and xml to hash using LibXML\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use XML::Hash::LX;\n\nmy $hash = xml2hash $xmlstring, attr => '.', text => '~';\nmy $hash = xml2hash $xmldoc;\n\nmy $xmlstr = hash2html $hash, attr => '+', text => '#text';\nmy $xmldoc = hash2html $hash, doc => 1, attr => '+';\n\n# Usage with XML::LibXML\n\nmy $doc = XML::LibXML->new->parsestring($xml);\nmy $xp  = XML::LibXML::XPathContext->new($doc);\n$xp->registerNs('rss', 'http://purl.org/rss/1.0/');\n\n# then process xpath\nfor ($xp->findnodes('//rss:item')) {\n# and convert to hash concrete nodes\nmy $item = xml2hash($);\nprint Dumper+$item\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module is a companion for \"XML::LibXML\". It operates with LibXML objects, could return or\naccept LibXML objects, and may be used for easy data transformations\n\nIt is faster in parsing then XML::Simple, XML::Hash, XML::Twig and of course much slower than\nXML::Bare ;)\n\nIt is faster in composing than XML::Hash, but slower than XML::Simple\n\nParse benchmark:\n\nRate   Simple     Hash     Twig Hash::LX     Bare\nSimple   11.3/s       --      -2%     -16%     -44%     -97%\nHash     11.6/s       2%       --     -14%     -43%     -97%\nTwig     13.5/s      19%      16%       --     -34%     -96%\nHash::LX 20.3/s      79%      75%      51%       --     -95%\nBare      370/s    3162%    3088%    2650%    1721%       --\n\nCompose benchmark:\n\nRate     Hash Hash::LX   Simple\nHash     49.2/s       --     -18%     -40%\nHash::LX 60.1/s      22%       --     -26%\nSimple   81.5/s      66%      36%       --\n\nBenchmark was done on <http://search.cpan.org/uploads.rdf>\n",
            "subsections": []
        },
        "EXPORT": {
            "content": "\"xml2hash\" and \"hash2xml\" are exported by default\n\n:inject\nInject toHash method in the namespace of XML::LibXML::Node and allow one to call it on any\nsubclass of XML::LibXML::Node directly\n\nBy default is disabled\n\nuse XML::Hash::LX ':inject';\n\nmy $doc = XML::LibXML->new->parsestring($xml);\nmy $hash = $doc->toHash(%opts);\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "xml2hash $xml, [ OPTIONS ]\nXML could be XML::LibXML::Document, XML::LibXML::DocumentPart or string\n\nhash2xml $hash, [ doc => 1, ] [ OPTIONS ]\nId \"doc\" option is true, then returned value is XML::LibXML::Document, not string\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "Every option could be passed as arguments to function or set as global variable in\n\"XML::Hash::LX\" namespace\n\n%XML::Hash::LX::X2H\nOptions respecting convertations from xml to hash\n\norder [ = 0 ]\nStrictly keep the output order. When enabled, structures become more complex, but xml could\nbe completely reverted\n\nattr [ = '-' ]\nAttribute prefix\n\n<node attr=\"test\" />  =>  { node => { -attr => \"test\" } }\n\ntext [ = '#text' ]\nKey name for storing text\n\n<node>text<sub /></node>  =>  { node => { sub => '', '#text' => \"test\" } }\n\njoin [ = '' ]\nJoin separator for text nodes, split by subnodes\n\nIgnored when \"order\" in effect\n\n# default:\nxml2hash( '<item>Test1<sub />Test2</item>' )\n: { item => { sub => '', '~' => 'Test1Test2' } };\n\n# global\n$XML::Hash::LX::X2H{join} = '+';\nxml2hash( '<item>Test1<sub />Test2</item>' )\n: { item => { sub => '', '~' => 'Test1+Test2' } };\n\n# argument\nxml2hash( '<item>Test1<sub />Test2</item>', join => '+' )\n: { item => { sub => '', '~' => 'Test1+Test2' } };\n\ntrim [ = 1 ]\nTrim leading and trailing whitespace from text nodes\n\ncdata [ = undef ]\nWhen defined, CDATA sections will be stored under this key\n\n# cdata = undef\n<node><![CDATA[ test ]]></node>  =>  { node => 'test' }\n\n# cdata = '#'\n<node><![CDATA[ test ]]></node>  =>  { node => { '#' => 'test' } }\n\ncomm [ = undef ]\nWhen defined, comments sections will be stored under this key\n\nWhen undef, comments will be ignored\n\n# comm = undef\n<node><!-- comm --><sub/></node>  =>  { node => { sub => '' } }\n\n# comm = '/'\n<node><!-- comm --><sub/></node>  =>  { node => { sub => '', '/' => 'comm' } }\n\n$XML::Hash::LX::X2A [ = 0 ]\nGlobal array casing\n\nIgnored when \"X2H{order}\" in effect\n\nAs option should be passed as\n\nxml2hash $xml, array => 1;\n\nEffect:\n\n# $X2A = 0\n<node><sub/></node>  =>  { node => { sub => '' } }\n\n# $X2A = 1\n<node><sub/></node>  =>  { node => [ { sub => [ '' ] } ] }\n\n%XML::Hash::LX::X2A\nBy element array casing\n\nIgnored when \"X2H{order}\" in effect\n\nAs option should be passed as\n\nxml2hash $xml, array => [ nodes list ];\n\nEffect:\n\n# %X2A = ()\n<node><sub/></node>  =>  { node => { sub => '' } }\n\n# %X2A = ( sub => 1 )\n<node><sub/></node>  =>  { node => { sub => [ '' ] } }\n\n%XML::Hash::LX::H2X\nOptions respecting convertations from hash to xml\n\nencoding [ = 'utf-8' ]\nXML output encoding\n\nattr [ = '-' ]\nAttribute prefix\n\n{ node => { -attr => \"test\", sub => 'test' } }\n<node attr=\"test\"><sub>test</sub></node>\n\ntext [ = '#text' ]\nKey name for storing text\n\n{ node => { sub => '', '#text' => \"test\" } }\n<node>text<sub /></node>\n# or\n<node><sub />text</node>\n# order of keys is not predictable\n\ntrim [ = 1 ]\nTrim leading and trailing whitespace from text nodes\n\n# trim = 1\n{ node => { sub => [ '    ', 'test' ], '#text' => \"test\" } }\n<node>test<sub>test</sub></node>\n\n# trim = 0\n{ node => { sub => [ '    ', 'test' ], '#text' => \"test\" } }\n<node>test<sub>    test</sub></node>\n\ncdata [ = undef ]\nWhen defined, such key elements will be saved as CDATA sections\n\n# cdata = undef\n{ node => { '#' => 'test' } } => <node><#>test</#></node> # it's bad ;)\n\n# cdata = '#'\n{ node => { '#' => 'test' } } => <node><![CDATA[test]]></node>\n\ncomm [ = undef ]\nWhen defined, such key elements will be saved as comment sections\n\n# comm = undef\n{ node => { '/' => 'test' } } => <node></>test<//></node> # it's very bad! ;)\n\n# comm = '/'\n{ node => { '/' => 'test' } } => <node><!-- test --></node>\n",
            "subsections": []
        },
        "BUGS": {
            "content": "None known\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "*   XML::Parser::Style::EasyTree\n\nWith default settings should produce the same output as this module. Settings are similar by\neffect\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Mons Anderson, \"<mons at cpan.org>\"\n\nCOPYRIGHT & LICENSE\nCopyright 2009 Mons Anderson, all rights reserved.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "XML::Hash::LX - Convert hash to xml and xml to hash using LibXML",
    "flags": [],
    "examples": [],
    "see_also": []
}