{
    "content": [
        {
            "type": "text",
            "text": "# HTML::TreeBuilder::XPath (perldoc)\n\n## NAME\n\nHTML::TreeBuilder::XPath - add XPath support to HTML::TreeBuilder\n\n## SYNOPSIS\n\nuse HTML::TreeBuilder::XPath;\nmy $tree= HTML::TreeBuilder::XPath->new;\n$tree->parsefile( \"mypage.html\");\nmy $nb=$tree->findvalue( '/html/body//p[@class=\"sectiontitle\"]/span[@class=\"nb\"]');\nmy $id=$tree->findvalue( '/html/body//p[@class=\"sectiontitle\"]/@id');\nmy $p= $html->findnodes( '//p[@id=\"toto\"]')->[0];\nmy $linktexts= $p->findvalue( './a'); # the texts of all a elements in $p\n$tree->delete; # to avoid memory leaks, if you parse many HTML documents\n\n## DESCRIPTION\n\nThis module adds typical XPath methods to HTML::TreeBuilder, to make it easy to query a\ndocument.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **SEE ALSO**\n- **REPOSITORY**\n- **AUTHOR**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "HTML::TreeBuilder::XPath",
        "section": "",
        "mode": "perldoc",
        "summary": "HTML::TreeBuilder::XPath - add XPath support to HTML::TreeBuilder",
        "synopsis": "use HTML::TreeBuilder::XPath;\nmy $tree= HTML::TreeBuilder::XPath->new;\n$tree->parsefile( \"mypage.html\");\nmy $nb=$tree->findvalue( '/html/body//p[@class=\"sectiontitle\"]/span[@class=\"nb\"]');\nmy $id=$tree->findvalue( '/html/body//p[@class=\"sectiontitle\"]/@id');\nmy $p= $html->findnodes( '//p[@id=\"toto\"]')->[0];\nmy $linktexts= $p->findvalue( './a'); # the texts of all a elements in $p\n$tree->delete; # to avoid memory leaks, if you parse many HTML documents",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 49,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "REPOSITORY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "HTML::TreeBuilder::XPath - add XPath support to HTML::TreeBuilder\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use HTML::TreeBuilder::XPath;\nmy $tree= HTML::TreeBuilder::XPath->new;\n$tree->parsefile( \"mypage.html\");\nmy $nb=$tree->findvalue( '/html/body//p[@class=\"sectiontitle\"]/span[@class=\"nb\"]');\nmy $id=$tree->findvalue( '/html/body//p[@class=\"sectiontitle\"]/@id');\n\nmy $p= $html->findnodes( '//p[@id=\"toto\"]')->[0];\nmy $linktexts= $p->findvalue( './a'); # the texts of all a elements in $p\n$tree->delete; # to avoid memory leaks, if you parse many HTML documents\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module adds typical XPath methods to HTML::TreeBuilder, to make it easy to query a\ndocument.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "Extra methods added both to the tree object and to each element:\n\nfindnodes ($path)\nReturns a list of nodes found by $path. In scalar context returns an\n\"Tree::XPathEngine::NodeSet\" object.\n\nfindnodesasstring ($path)\nReturns the text values of the nodes, as one string.\n\nfindnodesasstrings ($path)\nReturns a list of the values of the result nodes.\n\nfindvalue ($path)\nReturns either a \"Tree::XPathEngine::Literal\", a \"Tree::XPathEngine::Boolean\" or a\n\"Tree::XPathEngine::Number\" object. If the path returns a NodeSet, $nodeset->xpathtoliteral is\ncalled automatically for you (and thus a \"Tree::XPathEngine::Literal\" is returned). Note that\nfor each of the objects stringification is overloaded, so you can just print the value found, or\nmanipulate it in the ways you would a normal perl value (e.g. using regular expressions).\n\nfindvalues ($path)\nReturns the values of the matching nodes as a list. This is mostly the same as\nfindnodesasstrings, except that the elements of the list are objects (with overloaded\nstringification) instead of plain strings.\n\nexists ($path)\nReturns true if the given path exists.\n\nmatches($path)\nReturns true if the element matches the path.\n\nfind ($path)\nThe find function takes an XPath expression (a string) and returns either a\nTree::XPathEngine::NodeSet object containing the nodes it found (or empty if no nodes matched\nthe path), or one of XML::XPathEngine::Literal (a string), XML::XPathEngine::Number, or\nXML::XPathEngine::Boolean. It should always return something - and you can use ->isa() to find\nout what it returned. If you need to check how many nodes it found you should check\n$nodeset->size. See XML::XPathEngine::NodeSet.\n\nasXMLcompact\nHTML::TreeBuilder's \"asXML\" output is not really nice to look at, so I added a new method, that\ncan be used as a simple replacement for it. It escapes only the '<', '>' and '&' (plus '\"' in\nattribute values), and wraps CDATA elements in CDATA sections.\n\nNote that the XML is actually not garanteed to be valid at this point. Nothing is done about the\nencoding of the string. Patches or just ideas of how it could work are welcome.\n\nasXMLindented\nSame as asXML, except that the output is indented.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "HTML::TreeBuilder\n\nXML::XPathEngine\n",
                "subsections": []
            },
            "REPOSITORY": {
                "content": "<https://github.com/mirod/HTML--TreeBuilder--XPath>\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Michel Rodriguez, <mirod@cpan.org>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "Copyright (C) 2006-2011 by Michel Rodriguez\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may\nhave available.\n",
                "subsections": []
            }
        }
    }
}