{
    "content": [
        {
            "type": "text",
            "text": "# XML::XPath (perldoc)\n\n## NAME\n\nXML::XPath - Parse and evaluate XPath statements.\n\n## SYNOPSIS\n\nuse XML::XPath;\nuse XML::XPath::XMLParser;\nmy $xp = XML::XPath->new(filename => 'test.xhtml');\nmy $nodeset = $xp->find('/html/body/p'); # find all paragraphs\nforeach my $node ($nodeset->getnodelist) {\nprint \"FOUND\\n\\n\",\nXML::XPath::XMLParser::asstring($node),\n\"\\n\\n\";\n}\n\n## DESCRIPTION\n\nThis module aims to comply exactly to the XPath specification at http://www.w3.org/TR/xpath and\nyet allow extensions to be added in the form of functions.Modules such as XSLT and XPointer may\nneed to do this as they support functionality beyond XPath.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **DESCRIPTION**\n- **SYNOPSIS**\n- **DETAILS**\n- **METHODS**\n- **Node Object Model**\n- **On Garbage Collection**\n- **Example**\n- **AUTHOR**\n- **SEE ALSO**\n- **LICENSE AND COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "XML::XPath",
        "section": "",
        "mode": "perldoc",
        "summary": "XML::XPath - Parse and evaluate XPath statements.",
        "synopsis": "use XML::XPath;\nuse XML::XPath::XMLParser;\nmy $xp = XML::XPath->new(filename => 'test.xhtml');\nmy $nodeset = $xp->find('/html/body/p'); # find all paragraphs\nforeach my $node ($nodeset->getnodelist) {\nprint \"FOUND\\n\\n\",\nXML::XPath::XMLParser::asstring($node),\n\"\\n\\n\";\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "DETAILS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 79,
                "subsections": []
            },
            {
                "name": "Node Object Model",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "On Garbage Collection",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "Example",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "LICENSE AND COPYRIGHT",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "XML::XPath - Parse and evaluate XPath statements.\n",
                "subsections": []
            },
            "VERSION": {
                "content": "Version 1.44\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module aims to comply exactly to the XPath specification at http://www.w3.org/TR/xpath and\nyet allow extensions to be added in the form of functions.Modules such as XSLT and XPointer may\nneed to do this as they support functionality beyond XPath.\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use XML::XPath;\nuse XML::XPath::XMLParser;\n\nmy $xp = XML::XPath->new(filename => 'test.xhtml');\n\nmy $nodeset = $xp->find('/html/body/p'); # find all paragraphs\n\nforeach my $node ($nodeset->getnodelist) {\nprint \"FOUND\\n\\n\",\nXML::XPath::XMLParser::asstring($node),\n\"\\n\\n\";\n}\n",
                "subsections": []
            },
            "DETAILS": {
                "content": "There is an awful lot to all of this, so bear with it - if you stick it out it should be worth\nit. Please get a good understanding of XPath by reading the spec before asking me questions. All\nof the classes and parts herein are named to be synonymous with the names in the specification,\nso consult that if you don't understand why I'm doing something in the code.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "The API of XML::XPath itself is extremely simple to allow you to get going almost immediately.\nThe deeper API's are more complex, but you shouldn't have to touch most of that.\n\nnew()\nThis constructor follows the often seen named parameter method call. Parameters you can use are:\nfilename, parser, xml, ioref and context. The filename parameter specifies an XML file to parse.\nThe xml parameter specifies a string to parse, and the ioref parameter specifies an ioref to\nparse. The context option allows you to specify a context node. The context node has to be in\nthe format of a node as specified in XML::XPath::XMLParser. The 4 parameters filename, xml,\nioref and context are mutually exclusive - you should only specify one (if you specify anything\nother than context, the context node is the root of your document). The parser option allows you\nto pass in an already prepared XML::Parser object, to save you having to create more than one in\nyour application (if, for example, you are doing more than just XPath).\n\nmy $xp = XML::XPath->new( context => $node );\n\nIt is very much recommended that you use only 1 XPath object throughout the life of your\napplication. This is because the object (and it's sub-objects) maintain certain bits of state\ninformation that will be useful (such as XPath variables) to later calls to find(). It's also a\ngood idea because you'll use less memory this way.\n\nfind($path, [$context])\nThe find function takes an XPath expression (a string) and returns either an XML::XPath::NodeSet\nobject containing the nodes it found (or empty if no nodes matched the path), or one of\nXML::XPath::Literal (a string), XML::XPath::Number or XML::XPath::Boolean. It should always\nreturn something - and you can use ->isa() to find out what it returned. If you need to check\nhow many nodes it found you should check $nodeset->size. See XML::XPath::NodeSet. An optional\nsecond parameter of a context node allows you to use this method repeatedly, for example XSLT\nneeds to do this.\n\nfindnodes($path, [$context])\nReturns a list of nodes found by $path, optionally in context $context. In scalar context\nreturns an XML::XPath::NodeSet object.\n\nmatches($node, $path, [$context])\nReturns true if the node matches the path (optionally in context $context).\n\nfindnodesasstring($path, [$context])\nReturns the nodes found reproduced as XML.The result isn't guaranteed to be valid XML though.\n\nfindvalue($path, [$context])\nReturns either a \"XML::XPath::Literal\", a \"XML::XPath::Boolean\" or a \"XML::XPath::Number\"\nobject.If the path returns a NodeSet,$nodeset->toliteral is called automatically for you (and\nthus a \"XML::XPath::Literal\" is returned).Note that for each of the objects stringification is\noverloaded, so you can just print the value found, or manipulate it in the ways you would a\nnormal perl value (e.g. using regular expressions).\n\nexists($path, [$context])\nReturns true if the given path exists.\n\ngetNodeText($path)\nReturns the XML::XPath::Literal for a particular XML node. Returns a string if exists or ''\n(empty string) if the node doesn't exist.\n\nsetNodeText($path, $text)\nSets the text string for a particular XML node. The node can be an element or an attribute. If\nthe node to be set is an attribute, and the attribute node does not exist, it will be created\nautomatically.\n\ncreateNode($path)\nCreates the node matching the $path given. If part of the path given or all of the path do not\nexist, the necessary nodes will be created automatically.\n\nsetnamespace($prefix, $uri)\nSets the namespace prefix mapping to the uri.\n\nNormally in \"XML::XPath\" the prefixes in XPath node test take their context from the current\nnode. This means that foo:bar will always match an element <foo:bar> regardless of the namespace\nthat the prefix foo is mapped to (which might even change within the document, resulting in\nunexpected results). In order to make prefixes in XPath node tests actually map to a real URI,\nyou need to enable that via a call to the setnamespace method of your \"XML::XPath\" object.\n\nclearnamespaces()\nClears all previously set namespace mappings.\n\n$XML::XPath::Namespaces\nSet this to 0 if you *don't* want namespace processing to occur. This will make everything a\nlittle (tiny) bit faster, but you'll suffer for it, probably.\n",
                "subsections": []
            },
            "Node Object Model": {
                "content": "See XML::XPath::Node, XML::XPath::Node::Element, XML::XPath::Node::Text,\nXML::XPath::Node::Comment, XML::XPath::Node::Attribute, XML::XPath::Node::Namespace, and\nXML::XPath::Node::PI.\n",
                "subsections": []
            },
            "On Garbage Collection": {
                "content": "XPath nodes work in a special way that allows circular references, and yet still lets Perl's\nreference counting garbage collector to clean up the nodes after use. This should be totally\ntransparent to the user, with one caveat: If you free your tree before letting go of a\nsub-tree,consider that playing with fire and you may get burned. What does this mean to the\naverage user? Not much. Provided you don't free (or let go out of scope) either the tree you\npassed to XML::XPath->new, or if you didn't pass a tree, and passed a filename or IO-ref, then\nprovided you don't let the XML::XPath object go out of scope before you let results of find()\nand its friends go out of scope, then you'll be fine. Even if you do let the tree go out of\nscope before results, you'll probably still be fine. The only case where you may get stung is\nwhen the last part of your path/query is either an ancestor or parent axis. In that case the\nworst that will happen is you'll end up with a circular reference that won't get cleared until\ninterpreter destruction time.You can get around that by explicitly calling $node->DESTROY on\neach of your result nodes, if you really need to do that.\n\nMail me direct if that's not clear. Note that it's not doom and gloom. It's by no means\nperfect,but the worst that will happen is a long running process could leak memory. Most long\nrunning processes will therefore be able to explicitly be careful not to free the tree (or\nXML::XPath object) before freeing results.AxKit, an application that uses XML::XPath, does this\nand I didn't have to make any changes to the code - it's already sensible programming.\n\nIf you *really* don't want all this to happen, then set the variable $XML::XPath::SafeMode, and\ncall $xp->cleanup() on the XML::XPath object when you're finished, or $tree->dispose() if you\nhave a tree instead.\n",
                "subsections": []
            },
            "Example": {
                "content": "Please see the test files in t/ for examples on how to use XPath.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Original author Matt Sergeant, \"<matt at sergeant.org>\"\n\nCurrently maintained by Mohammad S Anwar, \"<mohammad.anwar at yahoo.com>\"\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "XML::XPath::Literal, XML::XPath::Boolean, XML::XPath::Number, XML::XPath::XMLParser,\nXML::XPath::NodeSet, XML::XPath::PerlSAX, XML::XPath::Builder.\n",
                "subsections": []
            },
            "LICENSE AND COPYRIGHT": {
                "content": "This module is copyright 2000 AxKit.com Ltd. This is free software, and as such comes with NO\nWARRANTY. No dates are used in this module. You may distribute this module under the terms of\neither the Gnu GPL, or the Artistic License (the same terms as Perl itself).\n\nFor support, please subscribe to the Perl-XML\n<http://listserv.activestate.com/mailman/listinfo/perl-xml> mailing list at the URL\n",
                "subsections": []
            }
        }
    }
}