{
    "mode": "perldoc",
    "parameter": "XML::LibXML",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML/json",
    "generated": "2026-06-10T04:28:34Z",
    "synopsis": "use XML::LibXML;\nmy $dom = XML::LibXML->loadxml(string => <<'EOT');\n<some-xml/>\nEOT\n$VersionString = XML::LibXML::LIBXMLDOTTEDVERSION;\n$VersionID = XML::LibXML::LIBXMLVERSION;\n$DLLVersion = XML::LibXML::LIBXMLRUNTIMEVERSION;\n$libxmlnode = XML::LibXML->importGDOME( $node, $deep );\n$gdomenode = XML::LibXML->exportGDOME( $node, $deep );",
    "sections": {
        "NAME": {
            "content": "XML::LibXML - Perl Binding for libxml2\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use XML::LibXML;\nmy $dom = XML::LibXML->loadxml(string => <<'EOT');\n<some-xml/>\nEOT\n\n$VersionString = XML::LibXML::LIBXMLDOTTEDVERSION;\n$VersionID = XML::LibXML::LIBXMLVERSION;\n$DLLVersion = XML::LibXML::LIBXMLRUNTIMEVERSION;\n$libxmlnode = XML::LibXML->importGDOME( $node, $deep );\n$gdomenode = XML::LibXML->exportGDOME( $node, $deep );\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module is an interface to libxml2, providing XML and HTML parsers with DOM, SAX and\nXMLReader interfaces, a large subset of DOM Layer 3 interface and a XML::XPath-like interface to\nXPath API of libxml2. The module is split into several packages which are not described in this\nsection; unless stated otherwise, you only need to \"use XML::LibXML;\" in your programs.\n\nFor further information, please check the following documentation:\n\nXML::LibXML::Parser\nParsing XML files with XML::LibXML\n\nXML::LibXML::DOM\nXML::LibXML Document Object Model (DOM) Implementation\n\nXML::LibXML::SAX\nXML::LibXML direct SAX parser\n\nXML::LibXML::Reader\nReading XML with a pull-parser\n\nXML::LibXML::Dtd\nXML::LibXML frontend for DTD validation\n\nXML::LibXML::RelaxNG\nXML::LibXML frontend for RelaxNG schema validation\n\nXML::LibXML::Schema\nXML::LibXML frontend for W3C Schema schema validation\n\nXML::LibXML::XPathContext\nAPI for evaluating XPath expressions with enhanced support for the evaluation context\n\nXML::LibXML::InputCallback\nImplementing custom URI Resolver and input callbacks\n\nXML::LibXML::Common\nCommon functions for XML::LibXML related Classes\n\nThe nodes in the Document Object Model (DOM) are represented by the following classes (most of\nwhich \"inherit\" from XML::LibXML::Node):\n\nXML::LibXML::Document\nXML::LibXML class for DOM document nodes\n\nXML::LibXML::Node\nAbstract base class for XML::LibXML DOM nodes\n\nXML::LibXML::Element\nXML::LibXML class for DOM element nodes\n\nXML::LibXML::Text\nXML::LibXML class for DOM text nodes\n\nXML::LibXML::Comment\nXML::LibXML class for comment DOM nodes\n\nXML::LibXML::CDATASection\nXML::LibXML class for DOM CDATA sections\n\nXML::LibXML::Attr\nXML::LibXML DOM attribute class\n\nXML::LibXML::DocumentFragment\nXML::LibXML's DOM L2 Document Fragment implementation\n\nXML::LibXML::Namespace\nXML::LibXML DOM namespace nodes\n\nXML::LibXML::PI\nXML::LibXML DOM processing instruction nodes\n\nENCODINGS SUPPORT IN XML::LIBXML\nRecall that since version 5.6.1, Perl distinguishes between character strings (internally\nencoded in UTF-8) and so called binary data and, accordingly, applies either character or byte\nsemantics to them. A scalar representing a character string is distinguished from a byte string\nby special flag (UTF8). Please refer to *perlunicode* for details.\n\nXML::LibXML's API is designed to deal with many encodings of XML documents completely\ntransparently, so that the application using XML::LibXML can be completely ignorant about the\nencoding of the XML documents it works with. On the other hand, functions like\n\"XML::LibXML::Document->setEncoding\" give the user control over the document encoding.\n\nTo ensure the aforementioned transparency and uniformity, most functions of XML::LibXML that\nwork with in-memory trees accept and return data as character strings (i.e. UTF-8 encoded with\nthe UTF8 flag on) regardless of the original document encoding; however, the functions related\nto I/O operations (i.e. parsing and saving) operate with binary data (in the original document\nencoding) obeying the encoding declaration of the XML documents.\n\nBelow we summarize basic rules and principles regarding encoding:\n\n1.  Do NOT apply any encoding-related PerlIO layers (\":utf8\" or \":encoding(...)\") to file\nhandles that are an input for the parses or an output for a serializer of (full) XML\ndocuments. This is because the conversion of the data to/from the internal character\nrepresentation is provided by libxml2 itself which must be able to enforce the encoding\nspecified by the \"<?xml version=\"1.0\" encoding=\"...\"?>\" declaration. Here is an example to\nfollow:\n\nuse XML::LibXML;\n# load\nopen my $fh, '<', 'file.xml';\nbinmode $fh; # drop all PerlIO layers possibly created by a use open pragma\n$doc = XML::LibXML->loadxml(IO => $fh);\n\n# save\nopen my $out, '>', 'out.xml';\nbinmode $out; # as above\n$doc->toFH($out);\n# or\nprint {$out} $doc->toString();\n\n2.  All functions working with DOM accept and return character strings (UTF-8 encoded with UTF8\nflag on). E.g.\n\nmy $doc = XML::LibXML::Document->new('1.0',$someencoding);\nmy $element = $doc->createElement($name);\n$element->appendText($text);\n$xmlfragment = $element->toString(); # returns a character string\n$xmldocument = $doc->toString(); # returns a byte string\n\nwhere $someencoding is the document encoding that will be used when saving the document,\nand $name and $text contain character strings (UTF-8 encoded with UTF8 flag on). Note that\nthe method \"toString\" returns XML as a character string if applied to other node than the\nDocument node and a byte string containing the appropriate\n\n<?xml version=\"1.0\" encoding=\"...\"?>\n\ndeclaration if applied to a XML::LibXML::Document.\n\n3.  DOM methods also accept binary strings in the original encoding of the document to which the\nnode belongs (UTF-8 is assumed if the node is not attached to any document). Exploiting this\nfeature is NOT RECOMMENDED since it is considered bad practice.\n\nmy $doc = XML::LibXML::Document->new('1.0','iso-8859-2');\nmy $text = $doc->createTextNode($somelatin2encodedbytestring);\n# WORKS, BUT NOT RECOMMENDED!\n\n*NOTE:* libxml2 support for many encodings is based on the iconv library. The actual list of\nsupported encodings may vary from platform to platform. To test if your platform works correctly\nwith your language encoding, build a simple document in the particular encoding and try to parse\nit with XML::LibXML to see if the parser produces any errors. Occasional crashes were reported\non rare platforms that ship with a broken version of iconv.\n",
            "subsections": []
        },
        "THREAD SUPPORT": {
            "content": "XML::LibXML since 1.67 partially supports Perl threads in Perl >= 5.8.8. XML::LibXML can be used\nwith threads in two ways:\n\nBy default, all XML::LibXML classes use CLONESKIP class method to prevent Perl from copying\nXML::LibXML::* objects when a new thread is spawn. In this mode, all XML::LibXML::* objects are\nthread specific. This is the safest way to work with XML::LibXML in threads.\n\nAlternatively, one may use\n\nuse threads;\nuse XML::LibXML qw(:threadsshared);\n\nto indicate, that all XML::LibXML node and parser objects should be shared between the main\nthread and any thread spawn from there. For example, in\n\nmy $doc = XML::LibXML->loadxml(location => $filename);\nmy $thr = threads->new(sub{\n# code working with $doc\n1;\n});\n$thr->join;\n\nthe variable $doc refers to the exact same XML::LibXML::Document in the spawned thread as in the\nmain thread.\n\nWithout using mutex locks, parallel threads may read the same document (i.e. any node that\nbelongs to the document), parse files, and modify different documents.\n\nHowever, if there is a chance that some of the threads will attempt to modify a document (or\neven create new nodes based on that document, e.g. with \"$doc->createElement\") that other\nthreads may be reading at the same time, the user is responsible for creating a mutex lock and\nusing it in *both* in the thread that modifies and the thread that reads:\n\nmy $doc = XML::LibXML->loadxml(location => $filename);\nmy $mutex : shared;\nmy $thr = threads->new(sub{\nlock $mutex;\nmy $el = $doc->createElement('foo');\n# ...\n1;\n});\n{\nlock $mutex;\nmy $root = $doc->documentElement;\nsay $root->name;\n}\n$thr->join;\n\nNote that libxml2 uses dictionaries to store short strings and these dictionaries are kept on a\ndocument node. Without mutex locks, it could happen in the previous example that the thread\nmodifies the dictionary while other threads attempt to read from it, which could easily lead to\na crash.\n",
            "subsections": []
        },
        "VERSION INFORMATION": {
            "content": "Sometimes it is useful to figure out, for which version XML::LibXML was compiled for. In most\ncases this is for debugging or to check if a given installation meets all functionality for the\npackage. The functions XML::LibXML::LIBXMLDOTTEDVERSION and XML::LibXML::LIBXMLVERSION\nprovide this version information. Both functions simply pass through the values of the similar\nnamed macros of libxml2. Similarly, XML::LibXML::LIBXMLRUNTIMEVERSION returns the version of\nthe (usually dynamically) linked libxml2.\n\nXML::LibXML::LIBXMLDOTTEDVERSION\n$VersionString = XML::LibXML::LIBXMLDOTTEDVERSION;\n\nReturns the version string of the libxml2 version XML::LibXML was compiled for. This will be\n\"2.6.2\" for \"libxml2 2.6.2\".\n\nXML::LibXML::LIBXMLVERSION\n$VersionID = XML::LibXML::LIBXMLVERSION;\n\nReturns the version id of the libxml2 version XML::LibXML was compiled for. This will be\n\"20602\" for \"libxml2 2.6.2\". Don't mix this version id with $XML::LibXML::VERSION. The\nlatter contains the version of XML::LibXML itself while the first contains the version of\nlibxml2 XML::LibXML was compiled for.\n\nXML::LibXML::LIBXMLRUNTIMEVERSION\n$DLLVersion = XML::LibXML::LIBXMLRUNTIMEVERSION;\n\nReturns a version string of the libxml2 which is (usually dynamically) linked by\nXML::LibXML. This will be \"20602\" for libxml2 released as \"2.6.2\" and something like\n\"20602-CVS2032\" for a CVS build of libxml2.\n\nXML::LibXML issues a warning if the version of libxml2 dynamically linked to it is less than\nthe version of libxml2 which it was compiled against.\n",
            "subsections": []
        },
        "EXPORTS": {
            "content": "By default the module exports all constants and functions listed in the :all tag, described\nbelow.\n",
            "subsections": []
        },
        "EXPORT TAGS": {
            "content": "\":all\"\nIncludes the tags \":libxml\", \":encoding\", and \":ns\" described below.\n\n\":libxml\"\nExports integer constants for DOM node types.\n\nXMLELEMENTNODE            => 1\nXMLATTRIBUTENODE          => 2\nXMLTEXTNODE               => 3\nXMLCDATASECTIONNODE      => 4\nXMLENTITYREFNODE         => 5\nXMLENTITYNODE             => 6\nXMLPINODE                 => 7\nXMLCOMMENTNODE            => 8\nXMLDOCUMENTNODE           => 9\nXMLDOCUMENTTYPENODE      => 10\nXMLDOCUMENTFRAGNODE      => 11\nXMLNOTATIONNODE           => 12\nXMLHTMLDOCUMENTNODE      => 13\nXMLDTDNODE                => 14\nXMLELEMENTDECL            => 15\nXMLATTRIBUTEDECL          => 16\nXMLENTITYDECL             => 17\nXMLNAMESPACEDECL          => 18\nXMLXINCLUDESTART          => 19\nXMLXINCLUDEEND            => 20\n\n\":encoding\"\nExports two encoding conversion functions from XML::LibXML::Common.\n\nencodeToUTF8()\ndecodeFromUTF8()\n\n\":ns\"\nExports two convenience constants: the implicit namespace of the reserved \"xml:\" prefix, and\nthe implicit namespace for the reserved \"xmlns:\" prefix.\n\nXMLXMLNS    => 'http://www.w3.org/XML/1998/namespace'\nXMLXMLNSNS  => 'http://www.w3.org/2000/xmlns/'\n",
            "subsections": []
        },
        "RELATED MODULES": {
            "content": "The modules described in this section are not part of the XML::LibXML package itself. As they\nsupport some additional features, they are mentioned here.\n\nXML::LibXSLT\nXSLT 1.0 Processor using libxslt and XML::LibXML\n\nXML::LibXML::Iterator\nXML::LibXML Implementation of the DOM Traversal Specification\n\nXML::CompactTree::XS\nUses XML::LibXML::Reader to very efficiently to parse XML document or element into native\nPerl data structures, which are less flexible but significantly faster to process then DOM.\n\nXML::LIBXML AND XML::GDOME\nNote: *THE FUNCTIONS DESCRIBED HERE ARE STILL EXPERIMENTAL*\n\nAlthough both modules make use of libxml2's XML capabilities, the DOM implementation of both\nmodules are not compatible. But still it is possible to exchange nodes from one DOM to the\nother. The concept of this exchange is pretty similar to the function cloneNode(): The\nparticular node is copied on the low-level to the opposite DOM implementation.\n\nSince the DOM implementations cannot coexist within one document, one is forced to copy each\nnode that should be used. Because you are always keeping two nodes this may cause quite an\nimpact on a machines memory usage.\n\nXML::LibXML provides two functions to export or import GDOME nodes: importGDOME() and",
            "subsections": [
                {
                    "name": "export_GDOME",
                    "content": "flag works as in cloneNode().\n\nThe two functions allow one to export and import XML::GDOME nodes explicitly, however,\nXML::LibXML also allows the transparent import of XML::GDOME nodes in functions such as"
                },
                {
                    "name": "appendChild",
                    "content": "functions XML::GDOME nodes are always cloned in advance. Thus if the original node is modified\nafter the operation, the node in the XML::LibXML document will not have this information.\n\nimportGDOME\n$libxmlnode = XML::LibXML->importGDOME( $node, $deep );\n\nThis clones an XML::GDOME node to an XML::LibXML node explicitly.\n\nexportGDOME\n$gdomenode = XML::LibXML->exportGDOME( $node, $deep );\n\nAllows one to clone an XML::LibXML node into an XML::GDOME node.\n"
                }
            ]
        },
        "CONTACTS": {
            "content": "For bug reports, please use the CPAN request tracker on\nhttp://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-LibXML\n\nFor suggestions etc., and other issues related to XML::LibXML you may use the perl XML mailing\nlist (\"perl-xml@listserv.ActiveState.com\"), where most XML-related Perl modules are discussed.\nIn case of problems you should check the archives of that list first. Many problems are already\ndiscussed there. You can find the list's archives and subscription options at\n<http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/perl-xml>.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Matt Sergeant, Christian Glahn, Petr Pajas\n",
            "subsections": []
        },
        "VERSION": {
            "content": "2.0134\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "2001-2007, AxKit.com Ltd.\n\n2002-2006, Christian Glahn.\n\n2006-2009, Petr Pajas.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "XML::LibXML - Perl Binding for libxml2",
    "flags": [],
    "examples": [],
    "see_also": []
}