{
    "content": [
        {
            "type": "text",
            "text": "# XML::Simple (perldoc)\n\n## NAME\n\nXML::Simple - An API for simple XML files\n\n## SYNOPSIS\n\nPLEASE DO NOT USE THIS MODULE IN NEW CODE. If you ignore this warning and use it anyway, the\n\"qw(:strict)\" mode will save you a little pain.\nuse XML::Simple qw(:strict);\nmy $ref = XMLin([<xml file or string>] [, <options>]);\nmy $xml = XMLout($hashref [, <options>]);\nOr the object oriented way:\nrequire XML::Simple qw(:strict);\nmy $xs = XML::Simple->new([<options>]);\nmy $ref = $xs->XMLin([<xml file or string>] [, <options>]);\nmy $xml = $xs->XMLout($hashref [, <options>]);\n(or see \"SAX SUPPORT\" for 'the SAX way').\nNote, in these examples, the square brackets are used to denote optional items not to imply\nitems should be supplied in arrayrefs.\n\n## DESCRIPTION\n\nThe XML::Simple module provides a simple API layer on top of an underlying XML parsing module\n(either XML::Parser or one of the SAX2 parser modules). Two functions are exported: \"XMLin()\"\nand \"XMLout()\". Note: you can explicitly request the lower case versions of the function names:\n\"xmlin()\" and \"xmlout()\".\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **STATUS OF THIS MODULE**\n- **QUICK START**\n- **DESCRIPTION** (1 subsections)\n- **OPTIONS**\n- **OPTIONAL OO INTERFACE** (16 subsections)\n- **STRICT MODE**\n- **SAX SUPPORT**\n- **ENVIRONMENT**\n- **ERROR HANDLING**\n- **EXAMPLES**\n- **SEE ALSO**\n- **COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "XML::Simple",
        "section": "",
        "mode": "perldoc",
        "summary": "XML::Simple - An API for simple XML files",
        "synopsis": "PLEASE DO NOT USE THIS MODULE IN NEW CODE. If you ignore this warning and use it anyway, the\n\"qw(:strict)\" mode will save you a little pain.\nuse XML::Simple qw(:strict);\nmy $ref = XMLin([<xml file or string>] [, <options>]);\nmy $xml = XMLout($hashref [, <options>]);\nOr the object oriented way:\nrequire XML::Simple qw(:strict);\nmy $xs = XML::Simple->new([<options>]);\nmy $ref = $xs->XMLin([<xml file or string>] [, <options>]);\nmy $xml = $xs->XMLout($hashref [, <options>]);\n(or see \"SAX SUPPORT\" for 'the SAX way').\nNote, in these examples, the square brackets are used to denote optional items not to imply\nitems should be supplied in arrayrefs.",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "When \"XMLin()\" reads the following very simple piece of XML:",
            "<opt username=\"testuser\" password=\"frodo\"></opt>",
            "it returns the following data structure:",
            "'username' => 'testuser',",
            "'password' => 'frodo'",
            "The identical result could have been produced with this alternative XML:",
            "<opt username=\"testuser\" password=\"frodo\" />",
            "Or this (although see 'ForceArray' option for variations):",
            "<opt>",
            "<username>testuser</username>",
            "<password>frodo</password>",
            "</opt>",
            "Repeated nested elements are represented as anonymous arrays:",
            "<opt>",
            "<person firstname=\"Joe\" lastname=\"Smith\">",
            "<email>joe@smith.com</email>",
            "<email>jsmith@yahoo.com</email>",
            "</person>",
            "<person firstname=\"Bob\" lastname=\"Smith\">",
            "<email>bob@smith.com</email>",
            "</person>",
            "</opt>",
            "'person' => [",
            "'email' => [",
            "'joe@smith.com',",
            "'jsmith@yahoo.com'",
            "],",
            "'firstname' => 'Joe',",
            "'lastname' => 'Smith'",
            "},",
            "'email' => 'bob@smith.com',",
            "'firstname' => 'Bob',",
            "'lastname' => 'Smith'",
            "Nested elements with a recognised key attribute are transformed (folded) from an array into a",
            "hash keyed on the value of that attribute (see the \"KeyAttr\" option):",
            "<opt>",
            "<person key=\"jsmith\" firstname=\"Joe\" lastname=\"Smith\" />",
            "<person key=\"tsmith\" firstname=\"Tom\" lastname=\"Smith\" />",
            "<person key=\"jbloggs\" firstname=\"Joe\" lastname=\"Bloggs\" />",
            "</opt>",
            "'person' => {",
            "'jbloggs' => {",
            "'firstname' => 'Joe',",
            "'lastname' => 'Bloggs'",
            "},",
            "'tsmith' => {",
            "'firstname' => 'Tom',",
            "'lastname' => 'Smith'",
            "},",
            "'jsmith' => {",
            "'firstname' => 'Joe',",
            "'lastname' => 'Smith'",
            "The <anon> tag can be used to form anonymous arrays:",
            "<opt>",
            "<head><anon>Col 1</anon><anon>Col 2</anon><anon>Col 3</anon></head>",
            "<data><anon>R1C1</anon><anon>R1C2</anon><anon>R1C3</anon></data>",
            "<data><anon>R2C1</anon><anon>R2C2</anon><anon>R2C3</anon></data>",
            "<data><anon>R3C1</anon><anon>R3C2</anon><anon>R3C3</anon></data>",
            "</opt>",
            "'head' => [",
            "[ 'Col 1', 'Col 2', 'Col 3' ]",
            "],",
            "'data' => [",
            "[ 'R1C1', 'R1C2', 'R1C3' ],",
            "[ 'R2C1', 'R2C2', 'R2C3' ],",
            "[ 'R3C1', 'R3C2', 'R3C3' ]",
            "Anonymous arrays can be nested to arbitrary levels and as a special case, if the surrounding",
            "tags for an XML document contain only an anonymous array the arrayref will be returned directly",
            "rather than the usual hashref:",
            "<opt>",
            "<anon><anon>Col 1</anon><anon>Col 2</anon></anon>",
            "<anon><anon>R1C1</anon><anon>R1C2</anon></anon>",
            "<anon><anon>R2C1</anon><anon>R2C2</anon></anon>",
            "</opt>",
            "[ 'Col 1', 'Col 2' ],",
            "[ 'R1C1', 'R1C2' ],",
            "[ 'R2C1', 'R2C2' ]",
            "Elements which only contain text content will simply be represented as a scalar. Where an",
            "element has both attributes and text content, the element will be represented as a hashref with",
            "the text content in the 'content' key (see the \"ContentKey\" option):",
            "<opt>",
            "<one>first</one>",
            "<two attr=\"value\">second</two>",
            "</opt>",
            "'one' => 'first',",
            "'two' => { 'attr' => 'value', 'content' => 'second' }",
            "Mixed content (elements which contain both text content and nested elements) will be not be",
            "represented in a useful way - element order and significant whitespace will be lost. If you need",
            "to work with mixed content, then XML::Simple is not the right tool for your job - check out the",
            "next section.",
            "WHERE TO FROM HERE?",
            "XML::Simple is able to present a simple API because it makes some assumptions on your behalf.",
            "These include:",
            "*   You're not interested in text content consisting only of whitespace",
            "*   You don't mind that when things get slurped into a hash the order is lost",
            "*   You don't want fine-grained control of the formatting of generated XML",
            "*   You would never use a hash key that was not a legal XML element name",
            "*   You don't need help converting between different encodings",
            "In a serious XML project, you'll probably outgrow these assumptions fairly quickly. This section",
            "of the document used to offer some advice on choosing a more powerful option. That advice has",
            "now grown into the 'Perl-XML FAQ' document which you can find at:",
            "<http://perl-xml.sourceforge.net/faq/>",
            "The advice in the FAQ boils down to a quick explanation of tree versus event based parsers and",
            "then recommends:",
            "For event based parsing, use SAX (do not set out to write any new code for XML::Parser's handler",
            "API - it is obsolete).",
            "For tree-based parsing, you could choose between the 'Perlish' approach of XML::Twig and more",
            "standards based DOM implementations - preferably one with XPath support such as XML::LibXML."
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "STATUS OF THIS MODULE",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "QUICK START",
                "lines": 87,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 58,
                "subsections": [
                    {
                        "name": "Caveats",
                        "lines": 27
                    }
                ]
            },
            {
                "name": "OPTIONS",
                "lines": 567,
                "subsections": []
            },
            {
                "name": "OPTIONAL OO INTERFACE",
                "lines": 28,
                "subsections": [
                    {
                        "name": "Parsing Methods",
                        "lines": 3
                    },
                    {
                        "name": "parse_string",
                        "lines": 3
                    },
                    {
                        "name": "parse_file",
                        "lines": 3
                    },
                    {
                        "name": "parse_fh",
                        "lines": 3
                    },
                    {
                        "name": "Hook Methods",
                        "lines": 5
                    },
                    {
                        "name": "new_xml_parser",
                        "lines": 3
                    },
                    {
                        "name": "handle_options",
                        "lines": 4
                    },
                    {
                        "name": "default_config_file",
                        "lines": 3
                    },
                    {
                        "name": "build_simple_tree",
                        "lines": 5
                    },
                    {
                        "name": "new_hashref",
                        "lines": 3
                    },
                    {
                        "name": "sorted_keys",
                        "lines": 3
                    },
                    {
                        "name": "escape_value",
                        "lines": 3
                    },
                    {
                        "name": "escape_attr",
                        "lines": 4
                    },
                    {
                        "name": "numeric_escape",
                        "lines": 3
                    },
                    {
                        "name": "copy_hash",
                        "lines": 3
                    },
                    {
                        "name": "Cache Methods",
                        "lines": 13
                    }
                ]
            },
            {
                "name": "STRICT MODE",
                "lines": 25,
                "subsections": []
            },
            {
                "name": "SAX SUPPORT",
                "lines": 80,
                "subsections": []
            },
            {
                "name": "ENVIRONMENT",
                "lines": 33,
                "subsections": []
            },
            {
                "name": "ERROR HANDLING",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 161,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "XML::Simple - An API for simple XML files\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "PLEASE DO NOT USE THIS MODULE IN NEW CODE. If you ignore this warning and use it anyway, the\n\"qw(:strict)\" mode will save you a little pain.\n\nuse XML::Simple qw(:strict);\n\nmy $ref = XMLin([<xml file or string>] [, <options>]);\n\nmy $xml = XMLout($hashref [, <options>]);\n\nOr the object oriented way:\n\nrequire XML::Simple qw(:strict);\n\nmy $xs = XML::Simple->new([<options>]);\n\nmy $ref = $xs->XMLin([<xml file or string>] [, <options>]);\n\nmy $xml = $xs->XMLout($hashref [, <options>]);\n\n(or see \"SAX SUPPORT\" for 'the SAX way').\n\nNote, in these examples, the square brackets are used to denote optional items not to imply\nitems should be supplied in arrayrefs.\n",
                "subsections": []
            },
            "STATUS OF THIS MODULE": {
                "content": "The use of this module in new code is strongly discouraged. Other modules are available which\nprovide more straightforward and consistent interfaces. In particular, XML::LibXML is highly\nrecommended and you can refer to Perl XML::LibXML by Example\n<http://grantm.github.io/perl-libxml-by-example/> for a tutorial introduction.\n\nXML::Twig is another excellent alternative.\n\nThe major problems with this module are the large number of options (some of which have\nunfortunate defaults) and the arbitrary ways in which these options interact - often producing\nunexpected results.\n\nPatches with bug fixes and documentation fixes are welcome, but new features are unlikely to be\nadded.\n",
                "subsections": []
            },
            "QUICK START": {
                "content": "Say you have a script called foo and a file of configuration options called foo.xml containing\nthe following:\n\n<config logdir=\"/var/log/foo/\" debugfile=\"/tmp/foo.debug\">\n<server name=\"sahara\" osname=\"solaris\" osversion=\"2.6\">\n<address>10.0.0.101</address>\n<address>10.0.1.101</address>\n</server>\n<server name=\"gobi\" osname=\"irix\" osversion=\"6.5\">\n<address>10.0.0.102</address>\n</server>\n<server name=\"kalahari\" osname=\"linux\" osversion=\"2.0.34\">\n<address>10.0.0.103</address>\n<address>10.0.1.103</address>\n</server>\n</config>\n\nThe following lines of code in foo:\n\nuse XML::Simple qw(:strict);\n\nmy $config = XMLin(undef, KeyAttr => { server => 'name' }, ForceArray => [ 'server', 'address' ]);\n\nwill 'slurp' the configuration options into the hashref $config (because no filename or XML\nstring was passed as the first argument to \"XMLin()\" the name and location of the XML file will\nbe inferred from name and location of the script). You can dump out the contents of the hashref\nusing Data::Dumper:\n\nuse Data::Dumper;\n\nprint Dumper($config);\n\nwhich will produce something like this (formatting has been adjusted for brevity):\n\n{\n'logdir'        => '/var/log/foo/',\n'debugfile'     => '/tmp/foo.debug',\n'server'        => {\n'sahara'        => {\n'osversion'     => '2.6',\n'osname'        => 'solaris',\n'address'       => [ '10.0.0.101', '10.0.1.101' ]\n},\n'gobi'          => {\n'osversion'     => '6.5',\n'osname'        => 'irix',\n'address'       => [ '10.0.0.102' ]\n},\n'kalahari'      => {\n'osversion'     => '2.0.34',\n'osname'        => 'linux',\n'address'       => [ '10.0.0.103', '10.0.1.103' ]\n}\n}\n}\n\nYour script could then access the name of the log directory like this:\n\nprint $config->{logdir};\n\nsimilarly, the second address on the server 'kalahari' could be referenced as:\n\nprint $config->{server}->{kalahari}->{address}->[1];\n\nNote: If the mapping between the output of Data::Dumper and the print statements above is not\nobvious to you, then please refer to the 'references' tutorial (AKA: \"Mark's very short tutorial\nabout references\") at perlreftut.\n\nIn this example, the \"ForceArray\" option was used to list elements that might occur multiple\ntimes and should therefore be represented as arrayrefs (even when only one element is present).\n\nThe \"KeyAttr\" option was used to indicate that each \"<server>\" element has a unique identifier\nin the \"name\" attribute. This allows you to index directly to a particular server record using\nthe name as a hash key (as shown above).\n\nFor simple requirements, that's really all there is to it. If you want to store your XML in a\ndifferent directory or file, or pass it in as a string or even pass it in via some derivative of\nan IO::Handle, you'll need to check out \"OPTIONS\". If you want to turn off or tweak the array\nfolding feature (that neat little transformation that produced $config->{server}) you'll find\noptions for that as well.\n\nIf you want to generate XML (for example to write a modified version of $config back out as\nXML), check out \"XMLout()\".\n\nIf your needs are not so simple, this may not be the module for you. In that case, you might\nwant to read \"WHERE TO FROM HERE?\".\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The XML::Simple module provides a simple API layer on top of an underlying XML parsing module\n(either XML::Parser or one of the SAX2 parser modules). Two functions are exported: \"XMLin()\"\nand \"XMLout()\". Note: you can explicitly request the lower case versions of the function names:\n\"xmlin()\" and \"xmlout()\".\n\nThe simplest approach is to call these two functions directly, but an optional object oriented\ninterface (see \"OPTIONAL OO INTERFACE\" below) allows them to be called as methods of an\nXML::Simple object. The object interface can also be used at either end of a SAX pipeline.\n\nXMLin()\nParses XML formatted data and returns a reference to a data structure which contains the same\ninformation in a more readily accessible form. (Skip down to \"EXAMPLES\" below, for more sample\ncode).\n\n\"XMLin()\" accepts an optional XML specifier followed by zero or more 'name => value' option\npairs. The XML specifier can be one of the following:\n\nA filename\nIf the filename contains no directory components \"XMLin()\" will look for the file in each\ndirectory in the SearchPath (see \"OPTIONS\" below) or in the current directory if the\nSearchPath option is not defined. eg:\n\n$ref = XMLin('/etc/params.xml');\n\nNote, the filename '-' can be used to parse from STDIN.\n\nundef\nIf there is no XML specifier, \"XMLin()\" will check the script directory and each of the\nSearchPath directories for a file with the same name as the script but with the extension\n'.xml'. Note: if you wish to specify options, you must specify the value 'undef'. eg:\n\n$ref = XMLin(undef, ForceArray => 1);\n\nA string of XML\nA string containing XML (recognised by the presence of '<' and '>' characters) will be\nparsed directly. eg:\n\n$ref = XMLin('<opt username=\"bob\" password=\"flurp\" />');\n\nAn IO::Handle object\nAn IO::Handle object will be read to EOF and its contents parsed. eg:\n\n$fh = IO::File->new('/etc/params.xml');\n$ref = XMLin($fh);\n\nXMLout()\nTakes a data structure (generally a hashref) and returns an XML encoding of that structure. If\nthe resulting XML is parsed using \"XMLin()\", it should return a data structure equivalent to the\noriginal (see caveats below).\n\nThe \"XMLout()\" function can also be used to output the XML as SAX events see the \"Handler\"\noption and \"SAX SUPPORT\" for more details).\n\nWhen translating hashes to XML, hash keys which have a leading '-' will be silently skipped.\nThis is the approved method for marking elements of a data structure which should be ignored by\n\"XMLout\". (Note: If these items were not skipped the key names would be emitted as element or\nattribute names with a leading '-' which would not be valid XML).\n",
                "subsections": [
                    {
                        "name": "Caveats",
                        "content": "Some care is required in creating data structures which will be passed to \"XMLout()\". Hash keys\nfrom the data structure will be encoded as either XML element names or attribute names.\nTherefore, you should use hash key names which conform to the relatively strict XML naming\nrules:\n\nNames in XML must begin with a letter. The remaining characters may be letters, digits, hyphens\n(-), underscores () or full stops (.). It is also allowable to include one colon (:) in an\nelement name but this should only be used when working with namespaces (XML::Simple can only\nusefully work with namespaces when teamed with a SAX Parser).\n\nYou can use other punctuation characters in hash values (just not in hash keys) however\nXML::Simple does not support dumping binary data.\n\nIf you break these rules, the current implementation of \"XMLout()\" will simply emit\nnon-compliant XML which will be rejected if you try to read it back in. (A later version of\nXML::Simple might take a more proactive approach).\n\nNote also that although you can nest hashes and arrays to arbitrary levels, circular data\nstructures are not supported and will cause \"XMLout()\" to die.\n\nIf you wish to 'round-trip' arbitrary data structures from Perl to XML and back to Perl, then\nyou should probably disable array folding (using the KeyAttr option) both with \"XMLout()\" and\nwith \"XMLin()\". If you still don't get the expected results, you may prefer to use XML::Dumper\nwhich is designed for exactly that purpose.\n\nRefer to \"WHERE TO FROM HERE?\" if \"XMLout()\" is too simple for your needs.\n"
                    }
                ]
            },
            "OPTIONS": {
                "content": "XML::Simple supports a number of options (in fact as each release of XML::Simple adds more\noptions, the module's claim to the name 'Simple' becomes increasingly tenuous). If you find\nyourself repeatedly having to specify the same options, you might like to investigate \"OPTIONAL\nOO INTERFACE\" below.\n\nIf you can't be bothered reading the documentation, refer to \"STRICT MODE\" to automatically\ncatch common mistakes.\n\nBecause there are so many options, it's hard for new users to know which ones are important, so\nhere are the two you really need to know about:\n\n*   check out \"ForceArray\" because you'll almost certainly want to turn it on\n\n*   make sure you know what the \"KeyAttr\" option does and what its default value is because it\nmay surprise you otherwise (note in particular that 'KeyAttr' affects both \"XMLin\" and\n\"XMLout\")\n\nThe option name headings below have a trailing 'comment' - a hash followed by two pieces of\nmetadata:\n\n*   Options are marked with '*in*' if they are recognised by \"XMLin()\" and '*out*' if they are\nrecognised by \"XMLout()\".\n\n*   Each option is also flagged to indicate whether it is:\n\n'important'   - don't use the module until you understand this one\n'handy'       - you can skip this on the first time through\n'advanced'    - you can skip this on the second time through\n'SAX only'    - don't worry about this unless you're using SAX (or\nalternatively if you need this, you also need SAX)\n'seldom used' - you'll probably never use this unless you were the\nperson that requested the feature\n\nThe options are listed alphabetically:\n\nNote: option names are no longer case sensitive so you can use the mixed case versions shown\nhere; all lower case as required by versions 2.03 and earlier; or you can add underscores\nbetween the words (eg: keyattr).\n\nAttrIndent => 1 *# out - handy*\nWhen you are using \"XMLout()\", enable this option to have attributes printed one-per-line with\nsensible indentation rather than all on one line.\n\nCache => [ cache schemes ] *# in - advanced*\nBecause loading the XML::Parser module and parsing an XML file can consume a significant number\nof CPU cycles, it is often desirable to cache the output of \"XMLin()\" for later reuse.\n\nWhen parsing from a named file, XML::Simple supports a number of caching schemes. The 'Cache'\noption may be used to specify one or more schemes (using an anonymous array). Each scheme will\nbe tried in turn in the hope of finding a cached pre-parsed representation of the XML file. If\nno cached copy is found, the file will be parsed and the first cache scheme in the list will be\nused to save a copy of the results. The following cache schemes have been implemented:\n\nstorable\nUtilises Storable.pm to read/write a cache file with the same name as the XML file but with\nthe extension .stor\n\nmemshare\nWhen a file is first parsed, a copy of the resulting data structure is retained in memory in\nthe XML::Simple module's namespace. Subsequent calls to parse the same file will return a\nreference to this structure. This cached version will persist only for the life of the Perl\ninterpreter (which in the case of modperl for example, may be some significant time).\n\nBecause each caller receives a reference to the same data structure, a change made by one\ncaller will be visible to all. For this reason, the reference returned should be treated as\nread-only.\n\nmemcopy\nThis scheme works identically to 'memshare' (above) except that each caller receives a\nreference to a new data structure which is a copy of the cached version. Copying the data\nstructure will add a little processing overhead, therefore this scheme should only be used\nwhere the caller intends to modify the data structure (or wishes to protect itself from\nothers who might). This scheme uses Storable.pm to perform the copy.\n\nWarning! The memory-based caching schemes compare the timestamp on the file to the time when it\nwas last parsed. If the file is stored on an NFS filesystem (or other network share) and the\nclock on the file server is not exactly synchronised with the clock where your script is run,\nupdates to the source XML file may appear to be ignored.\n\nContentKey => 'keyname' *# in+out - seldom used*\nWhen text content is parsed to a hash value, this option lets you specify a name for the hash\nkey to override the default 'content'. So for example:\n\nXMLin('<opt one=\"1\">Text</opt>', ContentKey => 'text')\n\nwill parse to:\n\n{ 'one' => 1, 'text' => 'Text' }\n\ninstead of:\n\n{ 'one' => 1, 'content' => 'Text' }\n\n\"XMLout()\" will also honour the value of this option when converting a hashref to XML.\n\nYou can also prefix your selected key name with a '-' character to have \"XMLin()\" try a little\nharder to eliminate unnecessary 'content' keys after array folding. For example:\n\nXMLin(\n'<opt><item name=\"one\">First</item><item name=\"two\">Second</item></opt>',\nKeyAttr => {item => 'name'},\nForceArray => [ 'item' ],\nContentKey => '-content'\n)\n\nwill parse to:\n\n{\n'item' => {\n'one' =>  'First'\n'two' =>  'Second'\n}\n}\n\nrather than this (without the '-'):\n\n{\n'item' => {\n'one' => { 'content' => 'First' }\n'two' => { 'content' => 'Second' }\n}\n}\n\nDataHandler => coderef *# in - SAX only*\nWhen you use an XML::Simple object as a SAX handler, it will return a 'simple tree' data\nstructure in the same format as \"XMLin()\" would return. If this option is set (to a subroutine\nreference), then when the tree is built the subroutine will be called and passed two arguments:\na reference to the XML::Simple object and a reference to the data tree. The return value from\nthe subroutine will be returned to the SAX driver. (See \"SAX SUPPORT\" for more details).\n\nForceArray => 1 *# in - important*\nThis option should be set to '1' to force nested elements to be represented as arrays even when\nthere is only one. Eg, with ForceArray enabled, this XML:\n\n<opt>\n<name>value</name>\n</opt>\n\nwould parse to this:\n\n{\n'name' => [\n'value'\n]\n}\n\ninstead of this (the default):\n\n{\n'name' => 'value'\n}\n\nThis option is especially useful if the data structure is likely to be written back out as XML\nand the default behaviour of rolling single nested elements up into attributes is not desirable.\n\nIf you are using the array folding feature, you should almost certainly enable this option. If\nyou do not, single nested elements will not be parsed to arrays and therefore will not be\ncandidates for folding to a hash. (Given that the default value of 'KeyAttr' enables array\nfolding, the default value of this option should probably also have been enabled too - sorry).\n\nForceArray => [ names ] *# in - important*\nThis alternative (and preferred) form of the 'ForceArray' option allows you to specify a list of\nelement names which should always be forced into an array representation, rather than the 'all\nor nothing' approach above.\n\nIt is also possible (since version 2.05) to include compiled regular expressions in the list -\nany element names which match the pattern will be forced to arrays. If the list contains only a\nsingle regex, then it is not necessary to enclose it in an arrayref. Eg:\n\nForceArray => qr/list$/\n\nForceContent => 1 *# in - seldom used*\nWhen \"XMLin()\" parses elements which have text content as well as attributes, the text content\nmust be represented as a hash value rather than a simple scalar. This option allows you to force\ntext content to always parse to a hash value even when there are no attributes. So for example:\n\nXMLin('<opt><x>text1</x><y a=\"2\">text2</y></opt>', ForceContent => 1)\n\nwill parse to:\n\n{\n'x' => {           'content' => 'text1' },\n'y' => { 'a' => 2, 'content' => 'text2' }\n}\n\ninstead of:\n\n{\n'x' => 'text1',\n'y' => { 'a' => 2, 'content' => 'text2' }\n}\n\nGroupTags => { grouping tag => grouped tag } *# in+out - handy*\nYou can use this option to eliminate extra levels of indirection in your Perl data structure.\nFor example this XML:\n\n<opt>\n<searchpath>\n<dir>/usr/bin</dir>\n<dir>/usr/local/bin</dir>\n<dir>/usr/X11/bin</dir>\n</searchpath>\n</opt>\n\nWould normally be read into a structure like this:\n\n{\nsearchpath => {\ndir => [ '/usr/bin', '/usr/local/bin', '/usr/X11/bin' ]\n}\n}\n\nBut when read in with the appropriate value for 'GroupTags':\n\nmy $opt = XMLin($xml, GroupTags => { searchpath => 'dir' });\n\nIt will return this simpler structure:\n\n{\nsearchpath => [ '/usr/bin', '/usr/local/bin', '/usr/X11/bin' ]\n}\n\nThe grouping element (\"<searchpath>\" in the example) must not contain any attributes or elements\nother than the grouped element.\n\nYou can specify multiple 'grouping element' to 'grouped element' mappings in the same hashref.\nIf this option is combined with \"KeyAttr\", the array folding will occur first and then the\ngrouped element names will be eliminated.\n\n\"XMLout\" will also use the grouptag mappings to re-introduce the tags around the grouped\nelements. Beware though that this will occur in all places that the 'grouping tag' name occurs -\nyou probably don't want to use the same name for elements as well as attributes.\n\nHandler => objectref *# out - SAX only*\nUse the 'Handler' option to have \"XMLout()\" generate SAX events rather than returning a string\nof XML. For more details see \"SAX SUPPORT\" below.\n\nNote: the current implementation of this option generates a string of XML and uses a SAX parser\nto translate it into SAX events. The normal encoding rules apply here - your data must be UTF8\nencoded unless you specify an alternative encoding via the 'XMLDecl' option; and by the time the\ndata reaches the handler object, it will be in UTF8 form regardless of the encoding you supply.\nA future implementation of this option may generate the events directly.\n\nKeepRoot => 1 *# in+out - handy*\nIn its attempt to return a data structure free of superfluous detail and unnecessary levels of\nindirection, \"XMLin()\" normally discards the root element name. Setting the 'KeepRoot' option to\n'1' will cause the root element name to be retained. So after executing this code:\n\n$config = XMLin('<config tempdir=\"/tmp\" />', KeepRoot => 1)\n\nYou'll be able to reference the tempdir as \"$config->{config}->{tempdir}\" instead of the default\n\"$config->{tempdir}\".\n\nSimilarly, setting the 'KeepRoot' option to '1' will tell \"XMLout()\" that the data structure\nalready contains a root element name and it is not necessary to add another.\n\nKeyAttr => [ list ] *# in+out - important*\nThis option controls the 'array folding' feature which translates nested elements from an array\nto a hash. It also controls the 'unfolding' of hashes to arrays.\n\nFor example, this XML:\n\n<opt>\n<user login=\"grep\" fullname=\"Gary R Epstein\" />\n<user login=\"stty\" fullname=\"Simon T Tyson\" />\n</opt>\n\nwould, by default, parse to this:\n\n{\n'user' => [\n{\n'login' => 'grep',\n'fullname' => 'Gary R Epstein'\n},\n{\n'login' => 'stty',\n'fullname' => 'Simon T Tyson'\n}\n]\n}\n\nIf the option 'KeyAttr => \"login\"' were used to specify that the 'login' attribute is a key, the\nsame XML would parse to:\n\n{\n'user' => {\n'stty' => {\n'fullname' => 'Simon T Tyson'\n},\n'grep' => {\n'fullname' => 'Gary R Epstein'\n}\n}\n}\n\nThe key attribute names should be supplied in an arrayref if there is more than one. \"XMLin()\"\nwill attempt to match attribute names in the order supplied. \"XMLout()\" will use the first\nattribute name supplied when 'unfolding' a hash into an array.\n\nNote 1: The default value for 'KeyAttr' is ['name', 'key', 'id']. If you do not want folding on\ninput or unfolding on output you must set this option to an empty list to disable the feature.\n\nNote 2: If you wish to use this option, you should also enable the \"ForceArray\" option. Without\n'ForceArray', a single nested element will be rolled up into a scalar rather than an array and\ntherefore will not be folded (since only arrays get folded).\n\nKeyAttr => { list } *# in+out - important*\nThis alternative (and preferred) method of specifying the key attributes allows more fine\ngrained control over which elements are folded and on which attributes. For example the option\n'KeyAttr => { package => 'id' } will cause any package elements to be folded on the 'id'\nattribute. No other elements which have an 'id' attribute will be folded at all.\n\nNote: \"XMLin()\" will generate a warning (or a fatal error in \"STRICT MODE\") if this syntax is\nused and an element which does not have the specified key attribute is encountered (eg: a\n'package' element without an 'id' attribute, to use the example above). Warnings can be\nsuppressed with the lexical \"no warnings;\" pragma or \"no warnings 'XML::Simple';\".\n\nTwo further variations are made possible by prefixing a '+' or a '-' character to the attribute\nname:\n\nThe option 'KeyAttr => { user => \"+login\" }' will cause this XML:\n\n<opt>\n<user login=\"grep\" fullname=\"Gary R Epstein\" />\n<user login=\"stty\" fullname=\"Simon T Tyson\" />\n</opt>\n\nto parse to this data structure:\n\n{\n'user' => {\n'stty' => {\n'fullname' => 'Simon T Tyson',\n'login'    => 'stty'\n},\n'grep' => {\n'fullname' => 'Gary R Epstein',\n'login'    => 'grep'\n}\n}\n}\n\nThe '+' indicates that the value of the key attribute should be copied rather than moved to the\nfolded hash key.\n\nA '-' prefix would produce this result:\n\n{\n'user' => {\n'stty' => {\n'fullname' => 'Simon T Tyson',\n'-login'    => 'stty'\n},\n'grep' => {\n'fullname' => 'Gary R Epstein',\n'-login'    => 'grep'\n}\n}\n}\n\nAs described earlier, \"XMLout\" will ignore hash keys starting with a '-'.\n\nNoAttr => 1 *# in+out - handy*\nWhen used with \"XMLout()\", the generated XML will contain no attributes. All hash key/values\nwill be represented as nested elements instead.\n\nWhen used with \"XMLin()\", any attributes in the XML will be ignored.\n\nNoEscape => 1 *# out - seldom used*\nBy default, \"XMLout()\" will translate the characters '<', '>', '&' and '\"' to '&lt;', '&gt;',\n'&amp;' and '&quot' respectively. Use this option to suppress escaping (presumably because\nyou've already escaped the data in some more sophisticated manner).\n\nNoIndent => 1 *# out - seldom used*\nSet this option to 1 to disable \"XMLout()\"'s default 'pretty printing' mode. With this option\nenabled, the XML output will all be on one line (unless there are newlines in the data) - this\nmay be easier for downstream processing.\n\nNoSort => 1 *# out - seldom used*\nNewer versions of XML::Simple sort elements and attributes alphabetically (*), by default.\nEnable this option to suppress the sorting - possibly for backwards compatibility.\n\n* Actually, sorting is alphabetical but 'key' attribute or element names (as in 'KeyAttr') sort\nfirst. Also, when a hash of hashes is 'unfolded', the elements are sorted alphabetically by the\nvalue of the key field.\n\nNormaliseSpace => 0 | 1 | 2 *# in - handy*\nThis option controls how whitespace in text content is handled. Recognised values for the option\nare:\n\n*   0 = (default) whitespace is passed through unaltered (except of course for the normalisation\nof whitespace in attribute values which is mandated by the XML recommendation)\n\n*   1 = whitespace is normalised in any value used as a hash key (normalising means removing\nleading and trailing whitespace and collapsing sequences of whitespace characters to a\nsingle space)\n\n*   2 = whitespace is normalised in all text content\n\nNote: you can spell this option with a 'z' if that is more natural for you.\n\nNSExpand => 1 *# in+out handy - SAX only*\nThis option controls namespace expansion - the translation of element and attribute names of the\nform 'prefix:name' to '{uri}name'. For example the element name 'xsl:template' might be expanded\nto: '{http://www.w3.org/1999/XSL/Transform}template'.\n\nBy default, \"XMLin()\" will return element names and attribute names exactly as they appear in\nthe XML. Setting this option to 1 will cause all element and attribute names to be expanded to\ninclude their namespace prefix.\n\n*Note: You must be using a SAX parser for this option to work (ie: it does not work with\nXML::Parser)*.\n\nThis option also controls whether \"XMLout()\" performs the reverse translation from '{uri}name'\nback to 'prefix:name'. The default is no translation. If your data contains expanded names, you\nshould set this option to 1 otherwise \"XMLout\" will emit XML which is not well formed.\n\n*Note: You must have the XML::NamespaceSupport module installed if you want \"XMLout()\" to\ntranslate URIs back to prefixes*.\n\nNumericEscape => 0 | 1 | 2 *# out - handy*\nUse this option to have 'high' (non-ASCII) characters in your Perl data structure converted to\nnumeric entities (eg: &#8364;) in the XML output. Three levels are possible:\n\n0 - default: no numeric escaping (OK if you're writing out UTF8)\n\n1 - only characters above 0xFF are escaped (ie: characters in the 0x80-FF range are not\nescaped), possibly useful with ISO8859-1 output\n\n2 - all characters above 0x7F are escaped (good for plain ASCII output)\n\nOutputFile => <file specifier> *# out - handy*\nThe default behaviour of \"XMLout()\" is to return the XML as a string. If you wish to write the\nXML to a file, simply supply the filename using the 'OutputFile' option.\n\nThis option also accepts an IO handle object - especially useful in Perl 5.8.0 and later for\noutput using an encoding other than UTF-8, eg:\n\nopen my $fh, '>:encoding(iso-8859-1)', $path or die \"open($path): $!\";\nXMLout($ref, OutputFile => $fh);\n\nNote, XML::Simple does not require that the object you pass in to the OutputFile option inherits\nfrom IO::Handle - it simply assumes the object supports a \"print\" method.\n\nParserOpts => [ XML::Parser Options ] *# in - don't use this*\n*Note: This option is now officially deprecated. If you find it useful, email the author with an\nexample of what you use it for. Do not use this option to set the ProtocolEncoding, that's just\nplain wrong - fix the XML*.\n\nThis option allows you to pass parameters to the constructor of the underlying XML::Parser\nobject (which of course assumes you're not using SAX).\n\nRootName => 'string' *# out - handy*\nBy default, when \"XMLout()\" generates XML, the root element will be named 'opt'. This option\nallows you to specify an alternative name.\n\nSpecifying either undef or the empty string for the RootName option will produce XML with no\nroot elements. In most cases the resulting XML fragment will not be 'well formed' and therefore\ncould not be read back in by \"XMLin()\". Nevertheless, the option has been found to be useful in\ncertain circumstances.\n\nSearchPath => [ list ] *# in - handy*\nIf you pass \"XMLin()\" a filename, but the filename include no directory component, you can use\nthis option to specify which directories should be searched to locate the file. You might use\nthis option to search first in the user's home directory, then in a global directory such as\n/etc.\n\nIf a filename is provided to \"XMLin()\" but SearchPath is not defined, the file is assumed to be\nin the current directory.\n\nIf the first parameter to \"XMLin()\" is undefined, the default SearchPath will contain only the\ndirectory in which the script itself is located. Otherwise the default SearchPath will be empty.\n\nStrictMode => 1 | 0  *# in+out seldom used*\nThis option allows you to turn \"STRICT MODE\" on or off for a particular call, regardless of\nwhether it was enabled at the time XML::Simple was loaded.\n\nSuppressEmpty => 1 | '' | undef *# in+out - handy*\nThis option controls what \"XMLin()\" should do with empty elements (no attributes and no\ncontent). The default behaviour is to represent them as empty hashes. Setting this option to a\ntrue value (eg: 1) will cause empty elements to be skipped altogether. Setting the option to\n'undef' or the empty string will cause empty elements to be represented as the undefined value\nor the empty string respectively. The latter two alternatives are a little easier to test for in\nyour code than a hash with no keys.\n\nThe option also controls what \"XMLout()\" does with undefined values. Setting the option to undef\ncauses undefined values to be output as empty elements (rather than empty attributes), it also\nsuppresses the generation of warnings about undefined values. Setting the option to a true value\n(eg: 1) causes undefined values to be skipped altogether on output.\n\nValueAttr => [ names ] *# in - handy*\nUse this option to deal elements which always have a single attribute and no content. Eg:\n\n<opt>\n<colour value=\"red\" />\n<size   value=\"XXL\" />\n</opt>\n\nSetting \"ValueAttr => [ 'value' ]\" will cause the above XML to parse to:\n\n{\ncolour => 'red',\nsize   => 'XXL'\n}\n\ninstead of this (the default):\n\n{\ncolour => { value => 'red' },\nsize   => { value => 'XXL' }\n}\n\nNote: This form of the ValueAttr option is not compatible with \"XMLout()\" - since the attribute\nname is discarded at parse time, the original XML cannot be reconstructed.\n\nValueAttr => { element => attribute, ... } *# in+out - handy*\nThis (preferred) form of the ValueAttr option requires you to specify both the element and the\nattribute names. This is not only safer, it also allows the original XML to be reconstructed by\n\"XMLout()\".\n\nNote: You probably don't want to use this option and the NoAttr option at the same time.\n\nVariables => { name => value } *# in - handy*\nThis option allows variables in the XML to be expanded when the file is read. (there is no\nfacility for putting the variable names back if you regenerate XML using \"XMLout\").\n\nA 'variable' is any text of the form \"${name}\" which occurs in an attribute value or in the text\ncontent of an element. If 'name' matches a key in the supplied hashref, \"${name}\" will be\nreplaced with the corresponding value from the hashref. If no matching key is found, the\nvariable will not be replaced. Names must match the regex: \"[\\w.]+\" (ie: only 'word' characters\nand dots are allowed).\n\nVarAttr => 'attrname' *# in - handy*\nIn addition to the variables defined using \"Variables\", this option allows variables to be\ndefined in the XML. A variable definition consists of an element with an attribute called\n'attrname' (the value of the \"VarAttr\" option). The value of the attribute will be used as the\nvariable name and the text content of the element will be used as the value. A variable defined\nin this way will override a variable defined using the \"Variables\" option. For example:\n\nXMLin( '<opt>\n<dir name=\"prefix\">/usr/local/apache</dir>\n<dir name=\"execprefix\">${prefix}</dir>\n<dir name=\"bindir\">${execprefix}/bin</dir>\n</opt>',\nVarAttr => 'name', ContentKey => '-content'\n);\n\nproduces the following data structure:\n\n{\ndir => {\nprefix      => '/usr/local/apache',\nexecprefix => '/usr/local/apache',\nbindir      => '/usr/local/apache/bin',\n}\n}\n\nXMLDecl => 1  or  XMLDecl => 'string'  *# out - handy*\nIf you want the output from \"XMLout()\" to start with the optional XML declaration, simply set\nthe option to '1'. The default XML declaration is:\n\n<?xml version='1.0' standalone='yes'?>\n\nIf you want some other string (for example to declare an encoding value), set the value of this\noption to the complete string you require.\n",
                "subsections": []
            },
            "OPTIONAL OO INTERFACE": {
                "content": "The procedural interface is both simple and convenient however there are a couple of reasons why\nyou might prefer to use the object oriented (OO) interface:\n\n*   to define a set of default values which should be used on all subsequent calls to \"XMLin()\"\nor \"XMLout()\"\n\n*   to override methods in XML::Simple to provide customised behaviour\n\nThe default values for the options described above are unlikely to suit everyone. The OO\ninterface allows you to effectively override XML::Simple's defaults with your preferred values.\nIt works like this:\n\nFirst create an XML::Simple parser object with your preferred defaults:\n\nmy $xs = XML::Simple->new(ForceArray => 1, KeepRoot => 1);\n\nthen call \"XMLin()\" or \"XMLout()\" as a method of that object:\n\nmy $ref = $xs->XMLin($xml);\nmy $xml = $xs->XMLout($ref);\n\nYou can also specify options when you make the method calls and these values will be merged with\nthe values specified when the object was created. Values specified in a method call take\nprecedence.\n\nNote: when called as methods, the \"XMLin()\" and \"XMLout()\" routines may be called as \"xmlin()\"\nor \"xmlout()\". The method names are aliased so the only difference is the aesthetics.\n",
                "subsections": [
                    {
                        "name": "Parsing Methods",
                        "content": "You can explicitly call one of the following methods rather than rely on the \"xmlin()\" method\nautomatically determining whether the target to be parsed is a string, a file or a filehandle:\n"
                    },
                    {
                        "name": "parse_string",
                        "content": "Works exactly like the \"xmlin()\" method but assumes the first argument is a string of XML\n(or a reference to a scalar containing a string of XML).\n"
                    },
                    {
                        "name": "parse_file",
                        "content": "Works exactly like the \"xmlin()\" method but assumes the first argument is the name of a\nfile containing XML.\n"
                    },
                    {
                        "name": "parse_fh",
                        "content": "Works exactly like the \"xmlin()\" method but assumes the first argument is a filehandle\nwhich can be read to get XML.\n"
                    },
                    {
                        "name": "Hook Methods",
                        "content": "You can make your own class which inherits from XML::Simple and overrides certain behaviours.\nThe following methods may provide useful 'hooks' upon which to hang your modified behaviour. You\nmay find other undocumented methods by examining the source, but those may be subject to change\nin future releases.\n"
                    },
                    {
                        "name": "new_xml_parser",
                        "content": "This method will be called when a new XML::Parser object must be constructed (either because\nXML::SAX is not installed or XML::Parser is preferred).\n"
                    },
                    {
                        "name": "handle_options",
                        "content": "This method will be called when one of the parsing methods or the \"XMLout()\" method is\ncalled. The initial argument will be a string (either 'in' or 'out') and the remaining\narguments will be name value pairs.\n"
                    },
                    {
                        "name": "default_config_file",
                        "content": "Calculates and returns the name of the file which should be parsed if no filename is passed\nto \"XMLin()\" (default: \"$0.xml\").\n"
                    },
                    {
                        "name": "build_simple_tree",
                        "content": "Called from \"XMLin()\" or any of the parsing methods. Takes either a file name as the first\nargument or \"undef\" followed by a 'string' as the second argument. Returns a simple tree\ndata structure. You could override this method to apply your own transformations before the\ndata structure is returned to the caller.\n"
                    },
                    {
                        "name": "new_hashref",
                        "content": "When the 'simple tree' data structure is being built, this method will be called to create\nany required anonymous hashrefs.\n"
                    },
                    {
                        "name": "sorted_keys",
                        "content": "Called when \"XMLout()\" is translating a hashref to XML. This routine returns a list of hash\nkeys in the order that the corresponding attributes/elements should appear in the output.\n"
                    },
                    {
                        "name": "escape_value",
                        "content": "Called from \"XMLout()\", takes a string and returns a copy of the string with XML character\nescaping rules applied.\n"
                    },
                    {
                        "name": "escape_attr",
                        "content": "Called from \"XMLout()\", to handle attribute values. By default, just calls \"escapevalue()\",\nbut you can override this method if you want attributes escaped differently than text\ncontent.\n"
                    },
                    {
                        "name": "numeric_escape",
                        "content": "Called from \"escapevalue()\", to handle non-ASCII characters (depending on the value of the\nNumericEscape option).\n"
                    },
                    {
                        "name": "copy_hash",
                        "content": "Called from \"XMLout()\", when 'unfolding' a hash of hashes into an array of hashes. You might\nwish to override this method if you're using tied hashes and don't want them to get untied.\n"
                    },
                    {
                        "name": "Cache Methods",
                        "content": "XML::Simple implements three caching schemes ('storable', 'memshare' and 'memcopy'). You can\nimplement a custom caching scheme by implementing two methods - one for reading from the cache\nand one for writing to it.\n\nFor example, you might implement a new 'dbm' scheme that stores cached data structures using the\nMLDBM module. First, you would add a \"cachereaddbm()\" method which accepted a filename for use\nas a lookup key and returned a data structure on success, or undef on failure. Then, you would\nimplement a \"cachereaddbm()\" method which accepted a data structure and a filename.\n\nYou would use this caching scheme by specifying the option:\n\nCache => [ 'dbm' ]\n"
                    }
                ]
            },
            "STRICT MODE": {
                "content": "If you import the XML::Simple routines like this:\n\nuse XML::Simple qw(:strict);\n\nthe following common mistakes will be detected and treated as fatal errors\n\n*   Failing to explicitly set the \"KeyAttr\" option - if you can't be bothered reading about this\noption, turn it off with: KeyAttr => [ ]\n\n*   Failing to explicitly set the \"ForceArray\" option - if you can't be bothered reading about\nthis option, set it to the safest mode with: ForceArray => 1\n\n*   Setting ForceArray to an array, but failing to list all the elements from the KeyAttr hash.\n\n*   Data error - KeyAttr is set to say { part => 'partnum' } but the XML contains one or more\n<part> elements without a 'partnum' attribute (or nested element). Note: if strict mode is\nnot set but \"use warnings;\" is in force, this condition triggers a warning.\n\n*   Data error - as above, but non-unique values are present in the key attribute (eg: more than\none <part> element with the same partnum). This will also trigger a warning if strict mode\nis not enabled.\n\n*   Data error - as above, but value of key attribute (eg: partnum) is not a scalar string (due\nto nested elements etc). This will also trigger a warning if strict mode is not enabled.\n",
                "subsections": []
            },
            "SAX SUPPORT": {
                "content": "From version 1.0801, XML::Simple includes support for SAX (the Simple API for XML) -\nspecifically SAX2.\n\nIn a typical SAX application, an XML parser (or SAX 'driver') module generates SAX events (start\nof element, character data, end of element, etc) as it parses an XML document and a 'handler'\nmodule processes the events to extract the required data. This simple model allows for some\ninteresting and powerful possibilities:\n\n*   Applications written to the SAX API can extract data from huge XML documents without the\nmemory overheads of a DOM or tree API.\n\n*   The SAX API allows for plug and play interchange of parser modules without having to change\nyour code to fit a new module's API. A number of SAX parsers are available with capabilities\nranging from extreme portability to blazing performance.\n\n*   A SAX 'filter' module can implement both a handler interface for receiving data and a\ngenerator interface for passing modified data on to a downstream handler. Filters can be\nchained together in 'pipelines'.\n\n*   One filter module might split a data stream to direct data to two or more downstream\nhandlers.\n\n*   Generating SAX events is not the exclusive preserve of XML parsing modules. For example, a\nmodule might extract data from a relational database using DBI and pass it on to a SAX\npipeline for filtering and formatting.\n\nXML::Simple can operate at either end of a SAX pipeline. For example, you can take a data\nstructure in the form of a hashref and pass it into a SAX pipeline using the 'Handler' option on\n\"XMLout()\":\n\nuse XML::Simple;\nuse Some::SAX::Filter;\nuse XML::SAX::Writer;\n\nmy $ref = {\n....   # your data here\n};\n\nmy $writer = XML::SAX::Writer->new();\nmy $filter = Some::SAX::Filter->new(Handler => $writer);\nmy $simple = XML::Simple->new(Handler => $filter);\n$simple->XMLout($ref);\n\nYou can also put XML::Simple at the opposite end of the pipeline to take advantage of the simple\n'tree' data structure once the relevant data has been isolated through filtering:\n\nuse XML::SAX;\nuse Some::SAX::Filter;\nuse XML::Simple;\n\nmy $simple = XML::Simple->new(ForceArray => 1, KeyAttr => ['partnum']);\nmy $filter = Some::SAX::Filter->new(Handler => $simple);\nmy $parser = XML::SAX::ParserFactory->parser(Handler => $filter);\n\nmy $ref = $parser->parseuri('somehugefile.xml');\n\nprint $ref->{part}->{'555-1234'};\n\nYou can build a filter by using an XML::Simple object as a handler and setting its DataHandler\noption to point to a routine which takes the resulting tree, modifies it and sends it off as SAX\nevents to a downstream handler:\n\nmy $writer = XML::SAX::Writer->new();\nmy $filter = XML::Simple->new(\nDataHandler => sub {\nmy $simple = shift;\nmy $data = shift;\n\n# Modify $data here\n\n$simple->XMLout($data, Handler => $writer);\n}\n);\nmy $parser = XML::SAX::ParserFactory->parser(Handler => $filter);\n\n$parser->parseuri($filename);\n\n*Note: In this last example, the 'Handler' option was specified in the call to \"XMLout()\" but it\ncould also have been specified in the constructor*.\n",
                "subsections": []
            },
            "ENVIRONMENT": {
                "content": "If you don't care which parser module XML::Simple uses then skip this section entirely (it looks\nmore complicated than it really is).\n\nXML::Simple will default to using a SAX parser if one is available or XML::Parser if SAX is not\navailable.\n\nYou can dictate which parser module is used by setting either the environment variable\n'XMLSIMPLEPREFERREDPARSER' or the package variable $XML::Simple::PREFERREDPARSER to contain\nthe module name. The following rules are used:\n\n*   The package variable takes precedence over the environment variable if both are defined. To\nforce XML::Simple to ignore the environment settings and use its default rules, you can set\nthe package variable to an empty string.\n\n*   If the 'preferred parser' is set to the string 'XML::Parser', then XML::Parser will be used\n(or \"XMLin()\" will die if XML::Parser is not installed).\n\n*   If the 'preferred parser' is set to some other value, then it is assumed to be the name of a\nSAX parser module and is passed to XML::SAX::ParserFactory. If XML::SAX is not installed, or\nthe requested parser module is not installed, then \"XMLin()\" will die.\n\n*   If the 'preferred parser' is not defined at all (the normal default state), an attempt will\nbe made to load XML::SAX. If XML::SAX is installed, then a parser module will be selected\naccording to XML::SAX::ParserFactory's normal rules (which typically means the last SAX\nparser installed).\n\n*   if the 'preferred parser' is not defined and XML::SAX is not installed, then XML::Parser\nwill be used. \"XMLin()\" will die if XML::Parser is not installed.\n\nNote: The XML::SAX distribution includes an XML parser written entirely in Perl. It is very\nportable but it is not very fast. You should consider installing XML::LibXML or XML::SAX::Expat\nif they are available for your platform.\n",
                "subsections": []
            },
            "ERROR HANDLING": {
                "content": "The XML standard is very clear on the issue of non-compliant documents. An error in parsing any\nsingle element (for example a missing end tag) must cause the whole document to be rejected.\nXML::Simple will die with an appropriate message if it encounters a parsing error.\n\nIf dying is not appropriate for your application, you should arrange to call \"XMLin()\" in an\neval block and look for errors in $@. eg:\n\nmy $config = eval { XMLin() };\nPopUpMessage($@) if($@);\n\nNote, there is a common misconception that use of eval will significantly slow down a script.\nWhile that may be true when the code being eval'd is in a string, it is not true of code like\nthe sample above.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "When \"XMLin()\" reads the following very simple piece of XML:\n\n<opt username=\"testuser\" password=\"frodo\"></opt>\n\nit returns the following data structure:\n\n{\n'username' => 'testuser',\n'password' => 'frodo'\n}\n\nThe identical result could have been produced with this alternative XML:\n\n<opt username=\"testuser\" password=\"frodo\" />\n\nOr this (although see 'ForceArray' option for variations):\n\n<opt>\n<username>testuser</username>\n<password>frodo</password>\n</opt>\n\nRepeated nested elements are represented as anonymous arrays:\n\n<opt>\n<person firstname=\"Joe\" lastname=\"Smith\">\n<email>joe@smith.com</email>\n<email>jsmith@yahoo.com</email>\n</person>\n<person firstname=\"Bob\" lastname=\"Smith\">\n<email>bob@smith.com</email>\n</person>\n</opt>\n\n{\n'person' => [\n{\n'email' => [\n'joe@smith.com',\n'jsmith@yahoo.com'\n],\n'firstname' => 'Joe',\n'lastname' => 'Smith'\n},\n{\n'email' => 'bob@smith.com',\n'firstname' => 'Bob',\n'lastname' => 'Smith'\n}\n]\n}\n\nNested elements with a recognised key attribute are transformed (folded) from an array into a\nhash keyed on the value of that attribute (see the \"KeyAttr\" option):\n\n<opt>\n<person key=\"jsmith\" firstname=\"Joe\" lastname=\"Smith\" />\n<person key=\"tsmith\" firstname=\"Tom\" lastname=\"Smith\" />\n<person key=\"jbloggs\" firstname=\"Joe\" lastname=\"Bloggs\" />\n</opt>\n\n{\n'person' => {\n'jbloggs' => {\n'firstname' => 'Joe',\n'lastname' => 'Bloggs'\n},\n'tsmith' => {\n'firstname' => 'Tom',\n'lastname' => 'Smith'\n},\n'jsmith' => {\n'firstname' => 'Joe',\n'lastname' => 'Smith'\n}\n}\n}\n\nThe <anon> tag can be used to form anonymous arrays:\n\n<opt>\n<head><anon>Col 1</anon><anon>Col 2</anon><anon>Col 3</anon></head>\n<data><anon>R1C1</anon><anon>R1C2</anon><anon>R1C3</anon></data>\n<data><anon>R2C1</anon><anon>R2C2</anon><anon>R2C3</anon></data>\n<data><anon>R3C1</anon><anon>R3C2</anon><anon>R3C3</anon></data>\n</opt>\n\n{\n'head' => [\n[ 'Col 1', 'Col 2', 'Col 3' ]\n],\n'data' => [\n[ 'R1C1', 'R1C2', 'R1C3' ],\n[ 'R2C1', 'R2C2', 'R2C3' ],\n[ 'R3C1', 'R3C2', 'R3C3' ]\n]\n}\n\nAnonymous arrays can be nested to arbitrary levels and as a special case, if the surrounding\ntags for an XML document contain only an anonymous array the arrayref will be returned directly\nrather than the usual hashref:\n\n<opt>\n<anon><anon>Col 1</anon><anon>Col 2</anon></anon>\n<anon><anon>R1C1</anon><anon>R1C2</anon></anon>\n<anon><anon>R2C1</anon><anon>R2C2</anon></anon>\n</opt>\n\n[\n[ 'Col 1', 'Col 2' ],\n[ 'R1C1', 'R1C2' ],\n[ 'R2C1', 'R2C2' ]\n]\n\nElements which only contain text content will simply be represented as a scalar. Where an\nelement has both attributes and text content, the element will be represented as a hashref with\nthe text content in the 'content' key (see the \"ContentKey\" option):\n\n<opt>\n<one>first</one>\n<two attr=\"value\">second</two>\n</opt>\n\n{\n'one' => 'first',\n'two' => { 'attr' => 'value', 'content' => 'second' }\n}\n\nMixed content (elements which contain both text content and nested elements) will be not be\nrepresented in a useful way - element order and significant whitespace will be lost. If you need\nto work with mixed content, then XML::Simple is not the right tool for your job - check out the\nnext section.\n\nWHERE TO FROM HERE?\nXML::Simple is able to present a simple API because it makes some assumptions on your behalf.\nThese include:\n\n*   You're not interested in text content consisting only of whitespace\n\n*   You don't mind that when things get slurped into a hash the order is lost\n\n*   You don't want fine-grained control of the formatting of generated XML\n\n*   You would never use a hash key that was not a legal XML element name\n\n*   You don't need help converting between different encodings\n\nIn a serious XML project, you'll probably outgrow these assumptions fairly quickly. This section\nof the document used to offer some advice on choosing a more powerful option. That advice has\nnow grown into the 'Perl-XML FAQ' document which you can find at:\n<http://perl-xml.sourceforge.net/faq/>\n\nThe advice in the FAQ boils down to a quick explanation of tree versus event based parsers and\nthen recommends:\n\nFor event based parsing, use SAX (do not set out to write any new code for XML::Parser's handler\nAPI - it is obsolete).\n\nFor tree-based parsing, you could choose between the 'Perlish' approach of XML::Twig and more\nstandards based DOM implementations - preferably one with XPath support such as XML::LibXML.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "XML::Simple requires either XML::Parser or XML::SAX.\n\nTo generate documents with namespaces, XML::NamespaceSupport is required.\n\nThe optional caching functions require Storable.\n\nAnswers to Frequently Asked Questions about XML::Simple are bundled with this distribution as:\nXML::Simple::FAQ\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright 1999-2004 Grant McLean <grantm@cpan.org>\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            }
        }
    }
}