{
    "mode": "perldoc",
    "parameter": "HTML::Element",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTML%3A%3AElement/json",
    "generated": "2026-06-11T05:35:28Z",
    "synopsis": "use HTML::Element;\n$a = HTML::Element->new('a', href => 'http://www.perl.com/');\n$a->pushcontent(\"The Perl Homepage\");\n$tag = $a->tag;\nprint \"$tag starts out as:\",  $a->starttag, \"\\n\";\nprint \"$tag ends as:\",  $a->endtag, \"\\n\";\nprint \"$tag\\'s href attribute is: \", $a->attr('href'), \"\\n\";\n$linksr = $a->extractlinks();\nprint \"Hey, I found \", scalar(@$linksr), \" links.\\n\";\nprint \"And that, as HTML, is: \", $a->asHTML, \"\\n\";\n$a = $a->delete;",
    "sections": {
        "NAME": {
            "content": "HTML::Element - Class for objects that represent HTML elements\n",
            "subsections": []
        },
        "VERSION": {
            "content": "This document describes version 5.07 of HTML::Element, released August 31, 2017 as part of\nHTML-Tree.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use HTML::Element;\n$a = HTML::Element->new('a', href => 'http://www.perl.com/');\n$a->pushcontent(\"The Perl Homepage\");\n\n$tag = $a->tag;\nprint \"$tag starts out as:\",  $a->starttag, \"\\n\";\nprint \"$tag ends as:\",  $a->endtag, \"\\n\";\nprint \"$tag\\'s href attribute is: \", $a->attr('href'), \"\\n\";\n\n$linksr = $a->extractlinks();\nprint \"Hey, I found \", scalar(@$linksr), \" links.\\n\";\n\nprint \"And that, as HTML, is: \", $a->asHTML, \"\\n\";\n$a = $a->delete;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "(This class is part of the HTML::Tree dist.)\n\nObjects of the HTML::Element class can be used to represent elements of HTML document trees.\nThese objects have attributes, notably attributes that designates each element's parent and\ncontent. The content is an array of text segments and other HTML::Element objects. A tree with\nHTML::Element objects as nodes can represent the syntax tree for a HTML document.\n",
            "subsections": []
        },
        "HOW WE REPRESENT TREES": {
            "content": "Consider this HTML document:\n\n<html lang='en-US'>\n<head>\n<title>Stuff</title>\n<meta name='author' content='Jojo'>\n</head>\n<body>\n<h1>I like potatoes!</h1>\n</body>\n</html>\n\nBuilding a syntax tree out of it makes a tree-structure in memory that could be diagrammed as:\n\nhtml (lang='en-US')\n/ \\\n/     \\\n/         \\\nhead        body\n/\\               \\\n/    \\               \\\n/        \\               \\\ntitle     meta              h1\n|       (name='author',     |\n\"Stuff\"    content='Jojo')    \"I like potatoes\"\n\nThis is the traditional way to diagram a tree, with the \"root\" at the top, and it's this kind of\ndiagram that people have in mind when they say, for example, that \"the meta element is under the\nhead element instead of under the body element\". (The same is also said with \"inside\" instead of\n\"under\" -- the use of \"inside\" makes more sense when you're looking at the HTML source.)\n\nAnother way to represent the above tree is with indenting:\n\nhtml (attributes: lang='en-US')\nhead\ntitle\n\"Stuff\"\nmeta (attributes: name='author' content='Jojo')\nbody\nh1\n\"I like potatoes\"\n\nIncidentally, diagramming with indenting works much better for very large trees, and is easier\nfor a program to generate. The \"$tree->dump\" method uses indentation just that way.\n\nHowever you diagram the tree, it's stored the same in memory -- it's a network of objects, each\nof which has attributes like so:\n\nelement #1:  tag: 'html'\nparent: none\ncontent: [element #2, element #5]\nlang: 'en-US'\n\nelement #2:  tag: 'head'\nparent: element #1\ncontent: [element #3, element #4]\n\nelement #3:  tag: 'title'\nparent: element #2\ncontent: [text segment \"Stuff\"]\n\nelement #4   tag: 'meta'\nparent: element #2\ncontent: none\nname: author\ncontent: Jojo\n\nelement #5   tag: 'body'\nparent: element #1\ncontent: [element #6]\n\nelement #6   tag: 'h1'\nparent: element #5\ncontent: [text segment \"I like potatoes\"]\n\nThe \"treeness\" of the tree-structure that these elements comprise is not an aspect of any\nparticular object, but is emergent from the relatedness attributes (parent and content) of\nthese element-objects and from how you use them to get from element to element.\n\nWhile you could access the content of a tree by writing code that says \"access the 'src'\nattribute of the root's *first* child's *seventh* child's *third* child\", you're more likely to\nhave to scan the contents of a tree, looking for whatever nodes, or kinds of nodes, you want to\ndo something with. The most straightforward way to look over a tree is to \"traverse\" it; an\nHTML::Element method (\"$h->traverse\") is provided for this purpose; and several other\nHTML::Element methods are based on it.\n\n(For everything you ever wanted to know about trees, and then some, see Niklaus Wirth's\n*Algorithms + Data Structures = Programs* or Donald Knuth's *The Art of Computer Programming,\nVolume 1*.)\n",
            "subsections": [
                {
                    "name": "Weak References",
                    "content": "TL;DR summary: \"use HTML::TreeBuilder 5 -weak;\" and forget about the \"delete\" method (except for\npruning a node from a tree).\n\nBecause HTML::Element stores a reference to the parent element, Perl's reference-count garbage\ncollection doesn't work properly with HTML::Element trees. Starting with version 5.00,\nHTML::Element uses weak references (if available) to prevent that problem. Weak references were\nintroduced in Perl 5.6.0, but you also need a version of Scalar::Util that provides the \"weaken\"\nfunction.\n\nWeak references are enabled by default. If you want to be certain they're in use, you can say\n\"use HTML::Element 5 -weak;\". You must include the version number; previous versions of\nHTML::Element ignored the import list entirely.\n\nTo disable weak references, you can say \"use HTML::Element -noweak;\". This is a global setting.\nThis feature is deprecated and is provided only as a quick fix for broken code. If your code\ndoes not work properly with weak references, you should fix it immediately, as weak references\nmay become mandatory in a future version. Generally, all you need to do is keep a reference to\nthe root of the tree until you're done working with it.\n\nBecause HTML::TreeBuilder is a subclass of HTML::Element, you can also import \"-weak\" or\n\"-noweak\" from HTML::TreeBuilder: e.g. \"use HTML::TreeBuilder: 5 -weak;\".\n"
                }
            ]
        },
        "BASIC METHODS": {
            "content": "new\n$h = HTML::Element->new('tag', 'attrname' => 'value', ... );\n\nThis constructor method returns a new HTML::Element object. The tag name is a required argument;\nit will be forced to lowercase. Optionally, you can specify other initial attributes at object\ncreation time.\n\nattr\n$value = $h->attr('attr');\n$oldvalue = $h->attr('attr', $newvalue);\n\nReturns (optionally sets) the value of the given attribute of $h. The attribute name (but not\nthe value, if provided) is forced to lowercase. If trying to read the value of an attribute not\npresent for this element, the return value is undef. If setting a new value, the old value of\nthat attribute is returned.\n\nIf methods are provided for accessing an attribute (like \"$h->tag\" for \"tag\",\n\"$h->contentlist\", etc. below), use those instead of calling attr \"$h->attr\", whether for\nreading or setting.\n\nNote that setting an attribute to \"undef\" (as opposed to \"\", the empty string) actually deletes\nthe attribute.\n\ntag\n$tagname = $h->tag();\n$h->tag('tagname');\n\nReturns (optionally sets) the tag name (also known as the generic identifier) for the element\n$h. In setting, the tag name is always converted to lower case.\n\nThere are four kinds of \"pseudo-elements\" that show up as HTML::Element objects:\n\nComment pseudo-elements\nThese are element objects with a \"$h->tag\" value of \"~comment\", and the content of the\ncomment is stored in the \"text\" attribute (\"$h->attr(\"text\")\"). For example, parsing this\ncode with HTML::TreeBuilder...\n\n<!-- I like Pie.\nPie is good\n-->\n\nproduces an HTML::Element object with these attributes:\n\n\"tag\",\n\"~comment\",\n\"text\",\n\" I like Pie.\\n     Pie is good\\n  \"\n\nDeclaration pseudo-elements\nDeclarations (rarely encountered) are represented as HTML::Element objects with a tag name\nof \"~declaration\", and content in the \"text\" attribute. For example, this:\n\n<!DOCTYPE foo>\n\nproduces an element whose attributes include:\n\n\"tag\", \"~declaration\", \"text\", \"DOCTYPE foo\"\n\nProcessing instruction pseudo-elements\nPIs (rarely encountered) are represented as HTML::Element objects with a tag name of \"~pi\",\nand content in the \"text\" attribute. For example, this:\n\n<?stuff foo?>\n\nproduces an element whose attributes include:\n\n\"tag\", \"~pi\", \"text\", \"stuff foo?\"\n\n(assuming a recent version of HTML::Parser)\n\n~literal pseudo-elements\nThese objects are not currently produced by HTML::TreeBuilder, but can be used to represent\na \"super-literal\" -- i.e., a literal you want to be immune from escaping. (Yes, I just made\nthat term up.)\n\nThat is, this is useful if you want to insert code into a tree that you plan to dump out\nwith \"asHTML\", where you want, for some reason, to suppress \"asHTML\"'s normal behavior of\namp-quoting text segments.\n\nFor example, this:\n\nmy $literal = HTML::Element->new('~literal',\n'text' => 'x < 4 & y > 7'\n);\nmy $span = HTML::Element->new('span');\n$span->pushcontent($literal);\nprint $span->asHTML;\n\nprints this:\n\n<span>x < 4 & y > 7</span>\n\nWhereas this:\n\nmy $span = HTML::Element->new('span');\n$span->pushcontent('x < 4 & y > 7');\n# normal text segment\nprint $span->asHTML;\n\nprints this:\n\n<span>x &lt; 4 &amp; y &gt; 7</span>\n\nUnless you're inserting lots of pre-cooked code into existing trees, and dumping them out\nagain, it's not likely that you'll find \"~literal\" pseudo-elements useful.\n\nparent\n$parent = $h->parent();\n$h->parent($newparent);\n\nReturns (optionally sets) the parent (aka \"container\") for this element. The parent should\neither be undef, or should be another element.\n\nYou should not use this to directly set the parent of an element. Instead use any of the other\nmethods under \"Structure-Modifying Methods\", below.\n\nNote that \"not($h->parent)\" is a simple test for whether $h is the root of its subtree.\n\ncontentlist\n@content = $h->contentlist();\n$numchildren = $h->contentlist();\n\nReturns a list of the child nodes of this element -- i.e., what nodes (elements or text\nsegments) are inside/under this element. (Note that this may be an empty list.)\n\nIn a scalar context, this returns the count of the items, as you may expect.\n\ncontent\n$contentarrayref = $h->content(); # may return undef\n\nThis somewhat deprecated method returns the content of this element; but unlike contentlist,\nthis returns either undef (which you should understand to mean no content), or a *reference to\nthe array* of content items, each of which is either a text segment (a string, i.e., a defined\nnon-reference scalar value), or an HTML::Element object. Note that even if an arrayref is\nreturned, it may be a reference to an empty array.\n\nWhile older code should feel free to continue to use \"$h->content\", new code should use\n\"$h->contentlist\" in almost all conceivable cases. It is my experience that in most cases this\nleads to simpler code anyway, since it means one can say:\n\n@children = $h->contentlist;\n\ninstead of the inelegant:\n\n@children = @{$h->content || []};\n\nIf you do use \"$h->content\" (or \"$h->contentarrayref\"), you should not use the reference\nreturned by it (assuming it returned a reference, and not undef) to directly set or change the\ncontent of an element or text segment! Instead use contentrefslist or any of the other methods\nunder \"Structure-Modifying Methods\", below.\n\ncontentarrayref\n$contentarrayref = $h->contentarrayref(); # never undef\n\nThis is like \"content\" (with all its caveats and deprecations) except that it is guaranteed to\nreturn an array reference. That is, if the given node has no \"content\" attribute, the \"content\"\nmethod would return that undef, but \"contentarrayref\" would set the given node's \"content\"\nvalue to \"[]\" (a reference to a new, empty array), and return that.\n\ncontentrefslist\n@contentrefs = $h->contentrefslist;\n\nThis returns a list of scalar references to each element of $h's content list. This is useful in\ncase you want to in-place edit any large text segments without having to get a copy of the\ncurrent value of that segment value, modify that copy, then use the \"splicecontent\" to replace\nthe old with the new. Instead, here you can in-place edit:\n\nforeach my $itemr ($h->contentrefslist) {\nnext if ref $$itemr;\n$$itemr =~ s/honour/honor/g;\n}\n\nYou *could* currently achieve the same affect with:\n\nforeach my $item (@{ $h->contentarrayref }) {\n# deprecated!\nnext if ref $item;\n$item =~ s/honour/honor/g;\n}\n\n...except that using the return value of \"$h->content\" or \"$h->contentarrayref\" to do that is\ndeprecated, and just might stop working in the future.\n\nimplicit\n$isimplicit = $h->implicit();\n$h->implicit($makeimplicit);\n\nReturns (optionally sets) the \"implicit\" attribute. This attribute is a flag that's used for\nindicating that the element was not originally present in the source, but was added to the parse\ntree (by HTML::TreeBuilder, for example) in order to conform to the rules of HTML structure.\n\npos\n$pos = $h->pos();\n$h->pos($element);\n\nReturns (and optionally sets) the \"pos\" (for \"current *pos*ition\") pointer of $h. This\nattribute is a pointer used during some parsing operations, whose value is whatever\nHTML::Element element at or under $h is currently \"open\", where \"$h->insertelement(NEW)\" will\nactually insert a new element.\n\n(This has nothing to do with the Perl function called \"pos\", for controlling where regular\nexpression matching starts.)\n\nIf you set \"$h->pos($element)\", be sure that $element is either $h, or an element under $h.\n\nIf you've been modifying the tree under $h and are no longer sure \"$h->pos\" is valid, you can\nenforce validity with:\n\n$h->pos(undef) unless $h->pos->isinside($h);\n\nallattr\n%attr = $h->allattr();\n\nReturns all this element's attributes and values, as key-value pairs. This will include any\n\"internal\" attributes (i.e., ones not present in the original element, and which will not be\nrepresented if/when you call \"$h->asHTML\"). Internal attributes are distinguished by the fact\nthat the first character of their key (not value! key!) is an underscore (\"\").\n\nExample output of \"$h->allattr()\" : \"'parent', \"*[objectvalue]*\" , 'tag', 'em', 'lang',\n'en-US', 'content', \"*[array-ref value]*.\n\nallattrnames\n@names = $h->allattrnames();\n$numattrs = $h->allattrnames();\n\nLike \"allattr\", but only returns the names of the attributes. In scalar context, returns the\nnumber of attributes.\n\nExample output of \"$h->allattrnames()\" : \"'parent', 'tag', 'lang', 'content', \".\n\nallexternalattr\n%attr = $h->allexternalattr();\n\nLike \"allattr\", except that internal attributes are not present.\n\nallexternalattrnames\n@names = $h->allexternalattrnames();\n$numattrs = $h->allexternalattrnames();\n\nLike \"allattrnames\", except that internal attributes' names are not present (or counted).\n\nid\n$id = $h->id();\n$h->id($string);\n\nReturns (optionally sets to $string) the \"id\" attribute. \"$h->id(undef)\" deletes the \"id\"\nattribute.\n\n\"$h->id(...)\" is basically equivalent to \"$h->attr('id', ...)\", except that when setting the\nattribute, this method returns the new value, not the old value.\n\nidf\n$id = $h->idf();\n$h->idf($string);\n\nJust like the \"id\" method, except that if you call \"$h->idf()\" and no \"id\" attribute is defined\nfor this element, then it's set to a likely-to-be-unique value, and returned. (The \"f\" is for\n\"force\".)\n",
            "subsections": []
        },
        "STRUCTURE-MODIFYING METHODS": {
            "content": "These methods are provided for modifying the content of trees by adding or changing nodes as\nparents or children of other nodes.\n\npushcontent\n$h->pushcontent($elementortext, ...);\n\nAdds the specified items to the *end* of the content list of the element $h. The items of\ncontent to be added should each be either a text segment (a string), an HTML::Element object, or\nan arrayref. Arrayrefs are fed thru \"$h->newfromlol(thatarrayref)\" to convert them into\nelements, before being added to the content list of $h. This means you can say things concise\nthings like:\n\n$body->pushcontent(\n['br'],\n['ul',\nmap ['li', $], qw(Peaches Apples Pears Mangos)\n]\n);\n\nSee the \"newfromlol\" method's documentation, far below, for more explanation.\n\nReturns $h (the element itself).\n\nThe pushcontent method will try to consolidate adjacent text segments while adding to the\ncontent list. That's to say, if $h's \"contentlist\" is\n\n('foo bar ', $somenode, 'baz!')\n\nand you call\n\n$h->pushcontent('quack?');\n\nthen the resulting content list will be this:\n\n('foo bar ', $somenode, 'baz!quack?')\n\nand not this:\n\n('foo bar ', $somenode, 'baz!', 'quack?')\n\nIf that latter is what you want, you'll have to override the feature of consolidating text by\nusing splicecontent, as in:\n\n$h->splicecontent(scalar($h->contentlist),0,'quack?');\n\nSimilarly, if you wanted to add 'Skronk' to the beginning of the content list, calling this:\n\n$h->unshiftcontent('Skronk');\n\nthen the resulting content list will be this:\n\n('Skronkfoo bar ', $somenode, 'baz!')\n\nand not this:\n\n('Skronk', 'foo bar ', $somenode, 'baz!')\n\nWhat you'd to do get the latter is:\n\n$h->splicecontent(0,0,'Skronk');\n\nunshiftcontent\n$h->unshiftcontent($elementortext, ...)\n\nJust like \"pushcontent\", but adds to the *beginning* of the $h element's content list.\n\nThe items of content to be added should each be either a text segment (a string), an\nHTML::Element object, or an arrayref (which is fed thru \"newfromlol\").\n\nThe unshiftcontent method will try to consolidate adjacent text segments while adding to the\ncontent list. See above for a discussion of this.\n\nReturns $h (the element itself).\n\nsplicecontent\n@removed = $h->splicecontent($offset, $length,\n$elementortext, ...);\n\nDetaches the elements from $h's list of content-nodes, starting at $offset and continuing for\n$length items, replacing them with the elements of the following list, if any. Returns the\nelements (if any) removed from the content-list. If $offset is negative, then it starts that far\nfrom the end of the array, just like Perl's normal \"splice\" function. If $length and the\nfollowing list is omitted, removes everything from $offset onward.\n\nThe items of content to be added (if any) should each be either a text segment (a string), an\narrayref (which is fed thru \"newfromlol\"), or an HTML::Element object that's not already a\nchild of $h.\n\ndetach\n$oldparent = $h->detach();\n\nThis unlinks $h from its parent, by setting its 'parent' attribute to undef, and by removing it\nfrom the content list of its parent (if it had one). The return value is the parent that was\ndetached from (or undef, if $h had no parent to start with). Note that neither $h nor its parent\nare explicitly destroyed.\n\ndetachcontent\n@oldcontent = $h->detachcontent();\n\nThis unlinks all of $h's children from $h, and returns them. Note that these are not explicitly\ndestroyed; for that, you can just use \"$h->deletecontent\".\n\nreplacewith\n$h->replacewith( $elementortext, ... )\n\nThis replaces $h in its parent's content list with the nodes specified. The element $h (which by\nthen may have no parent) is returned. This causes a fatal error if $h has no parent. The list of\nnodes to insert may contain $h, but at most once. Aside from that possible exception, the nodes\nto insert should not already be children of $h's parent.\n\nAlso, note that this method does not destroy $h if weak references are turned off -- use\n\"$h->replacewith(...)->delete\" if you need that.\n\npreinsert\n$h->preinsert($elementortext...);\n\nInserts the given nodes right BEFORE $h in $h's parent's content list. This causes a fatal error\nif $h has no parent. None of the given nodes should be $h or other children of $h. Returns $h.\n\npostinsert\n$h->postinsert($elementortext...)\n\nInserts the given nodes right AFTER $h in $h's parent's content list. This causes a fatal error\nif $h has no parent. None of the given nodes should be $h or other children of $h. Returns $h.\n\nreplacewithcontent\n$h->replacewithcontent();\n\nThis replaces $h in its parent's content list with its own content. The element $h (which by\nthen has no parent or content of its own) is returned. This causes a fatal error if $h has no\nparent. Also, note that this does not destroy $h if weak references are turned off -- use\n\"$h->replacewithcontent->delete\" if you need that.\n\ndeletecontent\n$h->deletecontent();\n$h->destroycontent(); # alias\n\nClears the content of $h, calling \"$h->delete\" for each content element. Compare with\n\"$h->detachcontent\".\n\nReturns $h.\n\n\"destroycontent\" is an alias for this method.\n\ndelete\n$h->delete();\n$h->destroy(); # alias\n\nDetaches this element from its parent (if it has one) and explicitly destroys the element and\nall its descendants. The return value is the empty list (or \"undef\" in scalar context).\n\nBefore version 5.00 of HTML::Element, you had to call \"delete\" when you were finished with the\ntree, or your program would leak memory. This is no longer necessary if weak references are\nenabled, see \"Weak References\".\n\ndestroy\nAn alias for \"delete\".\n\ndestroycontent\nAn alias for \"deletecontent\".\n\nclone\n$copy = $h->clone();\n\nReturns a copy of the element (whose children are clones (recursively) of the original's\nchildren, if any).\n\nThe returned element is parentless. Any 'pos' attributes present in the source element/tree\nwill be absent in the copy. For that and other reasons, the clone of an HTML::TreeBuilder object\nthat's in mid-parse (i.e, the head of a tree that HTML::TreeBuilder is elaborating) cannot\n(currently) be used to continue the parse.\n\nYou are free to clone HTML::TreeBuilder trees, just as long as: 1) they're done being parsed, or\n2) you don't expect to resume parsing into the clone. (You can continue parsing into the\noriginal; it is never affected.)\n\nclonelist\n@copies = HTML::Element->clonelist(...nodes...);\n\nReturns a list consisting of a copy of each node given. Text segments are simply copied;\nelements are cloned by calling \"$it->clone\" on each of them.\n\nNote that this must be called as a class method, not as an instance method. \"clonelist\" will\ncroak if called as an instance method. You can also call it like so:\n\nref($h)->clonelist(...nodes...)\n\nnormalizecontent\n$h->normalizecontent\n\nNormalizes the content of $h -- i.e., concatenates any adjacent text nodes. (Any undefined text\nsegments are turned into empty-strings.) Note that this does not recurse into $h's descendants.\n\ndeleteignorablewhitespace\n$h->deleteignorablewhitespace()\n\nThis traverses under $h and deletes any text segments that are ignorable whitespace. You should\nnot use this if $h is under a \"<pre>\" element.\n\ninsertelement\n$h->insertelement($element, $implicit);\n\nInserts (via pushcontent) a new element under the element at \"$h->pos()\". Then updates\n\"$h->pos()\" to point to the inserted element, unless $element is a prototypically empty element\nlike \"<br>\", \"<hr>\", \"<img>\", etc. The new \"$h->pos()\" is returned. This method is useful only\nif your particular tree task involves setting \"$h->pos()\".\n",
            "subsections": []
        },
        "DUMPING METHODS": {
            "content": "dump\n$h->dump()\n$h->dump(*FH)  ; # or *FH{IO} or $fhobj\n\nPrints the element and all its children to STDOUT (or to a specified filehandle), in a format\nuseful only for debugging. The structure of the document is shown by indentation (no end tags).\n\nasHTML\n$s = $h->asHTML();\n$s = $h->asHTML($entities);\n$s = $h->asHTML($entities, $indentchar);\n$s = $h->asHTML($entities, $indentchar, \\%optionalendtags);\n\nReturns a string representing in HTML the element and its descendants. The optional argument\n$entities specifies a string of the entities to encode. For compatibility with previous\nversions, specify '<>&' here. If omitted or undef, *all* unsafe characters are encoded as HTML\nentities. See HTML::Entities for details. If passed an empty string, no entities are encoded.\n\nIf $indentchar is specified and defined, the HTML to be output is intented, using the string\nyou specify (which you probably should set to \"\\t\", or some number of spaces, if you specify\nit).\n\nIf \"\\%optionalendtags\" is specified and defined, it should be a reference to a hash that holds\na true value for every tag name whose end tag is optional. Defaults to\n\"\\%HTML::Element::optionalEndTag\", which is an alias to %HTML::Tagset::optionalEndTag, which, at\ntime of writing, contains true values for \"p, li, dt, dd\". A useful value to pass is an empty\nhashref, \"{}\", which means that no end-tags are optional for this dump. Otherwise, possibly\nconsider copying %HTML::Tagset::optionalEndTag to a hash of your own, adding or deleting values\nas you like, and passing a reference to that hash.\n\nastext\n$s = $h->astext();\n$s = $h->astext(skipdels => 1);\n\nReturns a string consisting of only the text parts of the element's descendants. Any whitespace\ninside the element is included unchanged, but whitespace not in the tree is never added. But\nremember that whitespace may be ignored or compacted by HTML::TreeBuilder during parsing\n(depending on the value of the \"ignoreignorablewhitespace\" and \"nospacecompacting\"\nattributes). Also, since whitespace is never added during parsing,\n\nHTML::TreeBuilder->newfromcontent(\"<p>a</p><p>b</p>\")\n->astext;\n\nreturns \"ab\", not \"a b\" or \"a\\nb\".\n\nText under \"<script>\" or \"<style>\" elements is never included in what's returned. If \"skipdels\"\nis true, then text content under \"<del>\" nodes is not included in what's returned.\n\nastrimmedtext\n$s = $h->astrimmedtext(...);\n$s = $h->astrimmedtext(extrachars => '\\xA0'); # remove &nbsp;\n$s = $h->astexttrimmed(...); # alias\n\nThis is just like \"astext(...)\" except that leading and trailing whitespace is deleted, and any\ninternal whitespace is collapsed.\n\nThis will not remove non-breaking spaces, Unicode spaces, or any other non-ASCII whitespace\nunless you supply the extra characters as a string argument (e.g.\n\"$h->astrimmedtext(extrachars => '\\xA0')\"). \"extrachars\" may be any string that can appear\ninside a character class, including ranges like \"a-z\", POSIX character classes like \"[:alpha:]\",\nand character class escapes like \"\\p{Zs}\".\n\nasXML\n$s = $h->asXML()\n\nReturns a string representing in XML the element and its descendants.\n\nThe XML is not indented.\n\nasLispform\n$s = $h->asLispform();\n\nReturns a string representing the element and its descendants as a Lisp form. Unsafe characters\nare encoded as octal escapes.\n\nThe Lisp form is indented, and contains external (\"href\", etc.) as well as internal attributes\n(\"tag\", \"content\", \"implicit\", etc.), except for \"parent\", which is omitted.\n\nCurrent example output for a given element:\n\n(\"tag\" \"img\" \"border\" \"0\" \"src\" \"pie.png\" \"usemap\" \"#main.map\")\n\nformat\n$s = $h->format; # use HTML::FormatText\n$s = $h->format($formatter);\n\nFormats text output. Defaults to HTML::FormatText.\n\nTakes a second argument that is a reference to a formatter.\n\nstarttag\n$start = $h->starttag();\n$start = $h->starttag($entities);\n\nReturns a string representing the complete start tag for the element. I.e., leading \"<\", tag\nname, attributes, and trailing \">\". All values are surrounded with double-quotes, and\nappropriate characters are encoded. If $entities is omitted or undef, *all* unsafe characters\nare encoded as HTML entities. See HTML::Entities for details. If you specify some value for\n$entities, remember to include the double-quote character in it. (Previous versions of this\nmodule would basically behave as if '&\">' were specified for $entities.) If $entities is an\nempty string, no entity is escaped.\n\nstarttagXML\n$start = $h->starttagXML();\n\nReturns a string representing the complete start tag for the element.\n\nendtag\n$end = $h->endtag();\n\nReturns a string representing the complete end tag for this element. I.e., \"</\", tag name, and\n\">\".\n\nendtagXML\n$end = $h->endtagXML();\n\nReturns a string representing the complete end tag for this element. I.e., \"</\", tag name, and\n\">\".\n",
            "subsections": []
        },
        "SECONDARY STRUCTURAL METHODS": {
            "content": "These methods all involve some structural aspect of the tree; either they report some aspect of\nthe tree's structure, or they involve traversal down the tree, or walking up the tree.\n\nisinside\n$inside = $h->isinside('tag', $element, ...);\n\nReturns true if the $h element is, or is contained anywhere inside an element that is any of the\nones listed, or whose tag name is any of the tag names listed. You can use any mix of elements\nand tag names.\n\nisempty\n$empty = $h->isempty();\n\nReturns true if $h has no content, i.e., has no elements or text segments under it. In other\nwords, this returns true if $h is a leaf node, AKA a terminal node. Do not confuse this sense of\n\"empty\" with another sense that it can have in SGML/HTML/XML terminology, which means that the\nelement in question is of the type (like HTML's \"<hr>\", \"<br>\", \"<img>\", etc.) that *can't* have\nany content.\n\nThat is, a particular \"<p>\" element may happen to have no content, so $thatpelement->isempty\nwill be true -- even though the prototypical \"<p>\" element isn't \"empty\" (not in the way that\nthe prototypical \"<hr>\" element is).\n\nIf you think this might make for potentially confusing code, consider simply using the clearer\nexact equivalent: \"not($h->contentlist)\".\n\npindex\n$index = $h->pindex();\n\nReturn the index of the element in its parent's contents array, such that $h would equal\n\n$h->parent->content->[$h->pindex]\n# or\n($h->parent->contentlist)[$h->pindex]\n\nassuming $h isn't root. If the element $h is root, then \"$h->pindex\" returns \"undef\".\n\nleft\n$element = $h->left();\n@elements = $h->left();\n\nIn scalar context: returns the node that's the immediate left sibling of $h. If $h is the\nleftmost (or only) child of its parent (or has no parent), then this returns undef.\n\nIn list context: returns all the nodes that're the left siblings of $h (starting with the\nleftmost). If $h is the leftmost (or only) child of its parent (or has no parent), then this\nreturns an empty list.\n\n(See also \"$h->preinsert(LIST)\".)\n\nright\n$element = $h->right();\n@elements = $h->right();\n\nIn scalar context: returns the node that's the immediate right sibling of $h. If $h is the\nrightmost (or only) child of its parent (or has no parent), then this returns \"undef\".\n\nIn list context: returns all the nodes that're the right siblings of $h, starting with the\nleftmost. If $h is the rightmost (or only) child of its parent (or has no parent), then this\nreturns an empty list.\n\n(See also \"$h->postinsert(LIST)\".)\n\naddress\n$address = $h->address();\n$elementortext = $h->address($address);\n\nThe first form (with no parameter) returns a string representing the location of $h in the tree\nit is a member of. The address consists of numbers joined by a '.', starting with '0', and\nfollowed by the pindexes of the nodes in the tree that are ancestors of $h, starting from the\ntop.\n\nSo if the way to get to a node starting at the root is to go to child 2 of the root, then child\n10 of that, and then child 0 of that, and then you're there -- then that node's address is\n\"0.2.10.0\".\n\nAs a bit of a special case, the address of the root is simply \"0\".\n\nI forsee this being used mainly for debugging, but you may find your own uses for it.\n\n$elementortext = $h->address($address);\n\nThis form returns the node (whether element or text-segment) at the given address in the tree\nthat $h is a part of. (That is, the address is resolved starting from \"$h->root\".)\n\nIf there is no node at the given address, this returns \"undef\".\n\nYou can specify \"relative addressing\" (i.e., that indexing is supposed to start from $h and not\nfrom \"$h->root\") by having the address start with a period -- e.g., \"$h->address(\".3.2\")\" will\nlook at child 3 of $h, and child 2 of that.\n\ndepth\n$depth = $h->depth();\n\nReturns a number expressing $h's depth within its tree, i.e., how many steps away it is from the\nroot. If $h has no parent (i.e., is root), its depth is 0.\n\nroot\n$root = $h->root();\n\nReturns the element that's the top of $h's tree. If $h is root, this just returns $h. (If you\nwant to test whether $h *is* the root, instead of asking what its root is, just test\n\"not($h->parent)\".)\n\nlineage\n@lineage = $h->lineage();\n\nReturns the list of $h's ancestors, starting with its parent, and then that parent's parent, and\nso on, up to the root. If $h is root, this returns an empty list.\n\nIf you simply want a count of the number of elements in $h's lineage, use \"$h->depth\".\n\nlineagetagnames\n@names = $h->lineagetagnames();\n\nReturns the list of the tag names of $h's ancestors, starting with its parent, and that parent's\nparent, and so on, up to the root. If $h is root, this returns an empty list. Example output:\n\"('em', 'td', 'tr', 'table', 'body', 'html')\"\n\nEquivalent to:\n\nmap { $->tag } $h->lineage;\n\ndescendants\n@descendants = $h->descendants();\n\nIn list context, returns the list of all $h's descendant elements, listed in pre-order (i.e., an\nelement appears before its content-elements). Text segments DO NOT appear in the list. In scalar\ncontext, returns a count of all such elements.\n\ndescendents\nThis is just an alias to the \"descendants\" method, for people who can't spell.\n\nfindbytagname\n@elements = $h->findbytagname('tag', ...);\n$firstmatch = $h->findbytagname('tag', ...);\n\nIn list context, returns a list of elements at or under $h that have any of the specified tag\nnames. In scalar context, returns the first (in pre-order traversal of the tree) such element\nfound, or undef if none.\n\nfind\nThis is just an alias to \"findbytagname\". (There was once going to be a whole find* family\nof methods, but then \"lookdown\" filled that niche, so there turned out not to be much reason\nfor the verboseness of the name \"findbytagname\".)\n\nfindbyattribute\n@elements = $h->findbyattribute('attribute', 'value');\n$firstmatch = $h->findbyattribute('attribute', 'value');\n\nIn a list context, returns a list of elements at or under $h that have the specified attribute,\nand have the given value for that attribute. In a scalar context, returns the first (in\npre-order traversal of the tree) such element found, or undef if none.\n\nThis method is deprecated in favor of the more expressive \"lookdown\" method, which new code\nshould use instead.\n\nlookdown\n@elements = $h->lookdown( ...criteria... );\n$firstmatch = $h->lookdown( ...criteria... );\n\nThis starts at $h and looks thru its element descendants (in pre-order), looking for elements\nmatching the criteria you specify. In list context, returns all elements that match all the\ngiven criteria; in scalar context, returns the first such element (or undef, if nothing\nmatched).\n\nThere are three kinds of criteria you can specify:\n\n(attrname, attrvalue)\nThis means you're looking for an element with that value for that attribute. Example: \"alt\",\n\"pix!\". Consider that you can search on internal attribute values too: \"tag\", \"p\".\n\n(attrname, qr/.../)\nThis means you're looking for an element whose value for that attribute matches the\nspecified Regexp object.\n\na coderef\nThis means you're looking for elements where coderef->(eachelement) returns true. Example:\n\nmy @widepiximages = $h->lookdown(\ntag => \"img\",\nalt  => \"pix!\",\nsub { $[0]->attr('width') > 350 }\n);\n\nNote that \"(attrname, attrvalue)\" and \"(attrname, qr/.../)\" criteria are almost always faster\nthan coderef criteria, so should presumably be put before them in your list of criteria. That\nis, in the example above, the sub ref is called only for elements that have already passed the\ncriteria of having a \"tag\" attribute with value \"img\", and an \"alt\" attribute with value\n\"pix!\". If the coderef were first, it would be called on every element, and *then* what elements\npass that criterion (i.e., elements for which the coderef returned true) would be checked for\ntheir \"tag\" and \"alt\" attributes.\n\nNote that comparison of string attribute-values against the string value in \"(attrname,\nattrvalue)\" is case-INsensitive! A criterion of \"('align', 'right')\" *will* match an element\nwhose \"align\" value is \"RIGHT\", or \"right\" or \"rIGhT\", etc.\n\nNote also that \"lookdown\" considers \"\" (empty-string) and undef to be different things, in\nattribute values. So this:\n\n$h->lookdown(\"alt\", \"\")\n\nwill find elements *with* an \"alt\" attribute, but where the value for the \"alt\" attribute is \"\".\nBut this:\n\n$h->lookdown(\"alt\", undef)\n\nis the same as:\n\n$h->lookdown(sub { !defined($[0]->attr('alt')) } )\n\nThat is, it finds elements that do not have an \"alt\" attribute at all (or that do have an \"alt\"\nattribute, but with a value of undef -- which is not normally possible).\n\nNote that when you give several criteria, this is taken to mean you're looking for elements that\nmatch *all* your criterion, not just *any* of them. In other words, there is an implicit \"and\",\nnot an \"or\". So if you wanted to express that you wanted to find elements with a \"name\"\nattribute with the value \"foo\" *or* with an \"id\" attribute with the value \"baz\", you'd have to\ndo it like:\n\n@them = $h->lookdown(\nsub {\n# the lcs are to fold case\nlc($[0]->attr('name')) eq 'foo'\nor lc($[0]->attr('id')) eq 'baz'\n}\n);\n\nCoderef criteria are more expressive than \"(attrname, attrvalue)\" and \"(attrname, qr/.../)\"\ncriteria, and all \"(attrname, attrvalue)\" and \"(attrname, qr/.../)\" criteria could be\nexpressed in terms of coderefs. However, \"(attrname, attrvalue)\" and \"(attrname, qr/.../)\"\ncriteria are a convenient shorthand. (In fact, \"lookdown\" itself is basically \"shorthand\" too,\nsince anything you can do with \"lookdown\" you could do by traversing the tree, either with the\n\"traverse\" method or with a routine of your own. However, \"lookdown\" often makes for very\nconcise and clear code.)\n\nlookup\n@elements = $h->lookup( ...criteria... );\n$firstmatch = $h->lookup( ...criteria... );\n\nThis is identical to \"$h->lookdown\", except that whereas \"$h->lookdown\" basically scans over\nthe list:\n\n($h, $h->descendants)\n\n\"$h->lookup\" instead scans over the list\n\n($h, $h->lineage)\n\nSo, for example, this returns all ancestors of $h (possibly including $h itself) that are \"<td>\"\nelements with an \"align\" attribute with a value of \"right\" (or \"RIGHT\", etc.):\n\n$h->lookup(\"tag\", \"td\", \"align\", \"right\");\n\ntraverse\n$h->traverse(...options...)\n\nLengthy discussion of HTML::Element's unnecessary and confusing \"traverse\" method has been moved\nto a separate file: HTML::Element::traverse\n\nattrgeti\n@values = $h->attrgeti('attribute');\n$firstvalue = $h->attrgeti('attribute');\n\nIn list context, returns a list consisting of the values of the given attribute for $h and for\nall its ancestors starting from $h and working its way up. Nodes with no such attribute are\nskipped. (\"attrgeti\" stands for \"attribute get, with inheritance\".) In scalar context, returns\nthe first such value, or undef if none.\n\nConsider a document consisting of:\n\n<html lang='i-klingon'>\n<head><title>Pati Pata</title></head>\n<body>\n<h1 lang='la'>Stuff</h1>\n<p lang='es-MX' align='center'>\nFoo bar baz <cite>Quux</cite>.\n</p>\n<p>Hooboy.</p>\n</body>\n</html>\n\nIf $h is the \"<cite>\" element, \"$h->attrgeti(\"lang\")\" in list context will return the list\n\"('es-MX', 'i-klingon')\". In scalar context, it will return the value 'es-MX'.\n\nIf you call with multiple attribute names...\n\n@values = $h->attrgeti('a1', 'a2', 'a3');\n$firstvalue = $h->attrgeti('a1', 'a2', 'a3');\n\n...in list context, this will return a list consisting of the values of these attributes which\nexist in $h and its ancestors. In scalar context, this returns the first value (i.e., the value\nof the first existing attribute from the first element that has any of the attributes listed).\nSo, in the above example,\n\n$h->attrgeti('lang', 'align');\n\nwill return:\n\n('es-MX', 'center', 'i-klingon') # in list context\nor\n'es-MX' # in scalar context.\n\nBut note that this:\n\n$h->attrgeti('align', 'lang');\n\nwill return:\n\n('center', 'es-MX', 'i-klingon') # in list context\nor\n'center' # in scalar context.\n\ntagnamemap\n$hashref = $h->tagnamemap();\n\nScans across $h and all its descendants, and makes a hash (a reference to which is returned)\nwhere each entry consists of a key that's a tag name, and a value that's a reference to a list\nto all elements that have that tag name. I.e., this method returns:\n\n{\n# Across $h and all descendants...\n'a'   => [ ...list of all <a>   elements... ],\n'em'  => [ ...list of all <em>  elements... ],\n'img' => [ ...list of all <img> elements... ],\n}\n\n(There are entries in the hash for only those tagnames that occur at/under $h -- so if there's\nno \"<img>\" elements, there'll be no \"img\" entry in the returned hashref.)\n\nExample usage:\n\nmy $mapr = $h->tagnamemap();\nmy @headingtags = sort grep m/^h\\d$/s, keys %$mapr;\nif(@headingtags) {\nprint \"Heading levels used: @headingtags\\n\";\n} else {\nprint \"No headings.\\n\"\n}\n\nextractlinks\n$linksarrayref = $h->extractlinks();\n$linksarrayref = $h->extractlinks(@wantedTypes);\n\nReturns links found by traversing the element and all of its children and looking for attributes\n(like \"href\" in an \"<a>\" element, or \"src\" in an \"<img>\" element) whose values represent links.\nThe return value is a *reference* to an array. Each element of the array is reference to an\narray with *four* items: the link-value, the element that has the attribute with that\nlink-value, and the name of that attribute, and the tagname of that element. (Example:\n\"['http://www.suck.com/',\" *$elemobj* \", 'href', 'a']\".) You may or may not end up using the\nelement itself -- for some purposes, you may use only the link value.\n\nYou might specify that you want to extract links from just some kinds of elements (instead of\nthe default, which is to extract links from *all* the kinds of elements known to have attributes\nwhose values represent links). For instance, if you want to extract links from only \"<a>\" and\n\"<img>\" elements, you could code it like this:\n\nfor (@{  $e->extractlinks('a', 'img')  }) {\nmy($link, $element, $attr, $tag) = @$;\nprint\n\"Hey, there's a $tag that links to \",\n$link, \", in its $attr attribute, at \",\n$element->address(), \".\\n\";\n}\n\nsimplifypres\n$h->simplifypres();\n\nIn text bits under PRE elements that are at/under $h, this routine nativizes all newlines, and\nexpands all tabs.\n\nThat is, if you read a file with lines delimited by \"\\cm\\cj\"'s, the text under PRE areas will\nhave \"\\cm\\cj\"'s instead of \"\\n\"'s. Calling \"$h->simplifypres\" on such a tree will turn\n\"\\cm\\cj\"'s into \"\\n\"'s.\n\nTabs are expanded to however many spaces it takes to get to the next 8th column -- the usual way\nof expanding them.\n\nsameas\n$equal = $h->sameas($i)\n\nReturns true if $h and $i are both elements representing the same tree of elements, each with\nthe same tag name, with the same explicit attributes (i.e., not counting attributes whose names\nstart with \"\"), and with the same content (textual, comments, etc.).\n\nSameness of descendant elements is tested, recursively, with \"$child1->sameas($child2)\", and\nsameness of text segments is tested with \"$segment1 eq $segment2\".\n\nnewfromlol\n$h = HTML::Element->newfromlol($arrayref);\n@elements = HTML::Element->newfromlol($arrayref, ...);\n\nRecursively constructs a tree of nodes, based on the (non-cyclic) data structure represented by\neach $arrayref, where that is a reference to an array of arrays (of arrays (of arrays (etc.))).\n\nIn each arrayref in that structure, different kinds of values are treated as follows:\n\n*   Arrayrefs\n\nArrayrefs are considered to designate a sub-tree representing children for the node\nconstructed from the current arrayref.\n\n*   Hashrefs\n\nHashrefs are considered to contain attribute-value pairs to add to the element to be\nconstructed from the current arrayref\n\n*   Text segments\n\nText segments at the start of any arrayref will be considered to specify the name of the\nelement to be constructed from the current arrayref; all other text segments will be\nconsidered to specify text segments as children for the current arrayref.\n\n*   Elements\n\nExisting element objects are either inserted into the treelet constructed, or clones of them\nare. That is, when the lol-tree is being traversed and elements constructed based what's in\nit, if an existing element object is found, if it has no parent, then it is added directly\nto the treelet constructed; but if it has a parent, then \"$thatnode->clone\" is added to the\ntreelet at the appropriate place.\n\nAn example will hopefully make this more obvious:\n\nmy $h = HTML::Element->newfromlol(\n['html',\n['head',\n[ 'title', 'I like stuff!' ],\n],\n['body',\n{'lang', 'en-JP', implicit => 1},\n'stuff',\n['p', 'um, p < 4!', {'class' => 'par123'}],\n['div', {foo => 'bar'}, '123'],\n]\n]\n);\n$h->dump;\n\nWill print this:\n\n<html> @0\n<head> @0.0\n<title> @0.0.0\n\"I like stuff!\"\n<body lang=\"en-JP\"> @0.1 (IMPLICIT)\n\"stuff\"\n<p class=\"par123\"> @0.1.1\n\"um, p < 4!\"\n<div foo=\"bar\"> @0.1.2\n\"123\"\n\nAnd printing $h->asHTML will give something like:\n\n<html><head><title>I like stuff!</title></head>\n<body lang=\"en-JP\">stuff<p class=\"par123\">um, p &lt; 4!\n<div foo=\"bar\">123</div></body></html>\n\nYou can even do fancy things with \"map\":\n\n$body->pushcontent(\n# pushcontent implicitly calls newfromlol on arrayrefs...\n['br'],\n['blockquote',\n['h2', 'Pictures!'],\nmap ['p', $],\n$body2->lookdown(\"tag\", \"img\"),\n# images, to be copied from that other tree.\n],\n# and more stuff:\n['ul',\nmap ['li', ['a', {'href'=>\"$.png\"}, $ ] ],\nqw(Peaches Apples Pears Mangos)\n],\n);\n\nIn scalar context, you must supply exactly one arrayref. In list context, you can pass a list of\narrayrefs, and newfromlol will return a list of elements, one for each arrayref.\n\n@elements = HTML::Element->newfromlol(\n['hr'],\n['p', 'And there, on the door, was a hook!'],\n);\n# constructs two elements.\n\nobjectifytext\n$h->objectifytext();\n\nThis turns any text nodes under $h from mere text segments (strings) into real objects,\npseudo-elements with a tag-name of \"~text\", and the actual text content in an attribute called\n\"text\". (For a discussion of pseudo-elements, see the \"tag\" method, far above.) This method is\nprovided because, for some purposes, it is convenient or necessary to be able, for a given text\nnode, to ask what element is its parent; and clearly this is not possible if a node is just a\ntext string.\n\nNote that these \"~text\" objects are not recognized as text nodes by methods like \"astext\".\nPresumably you will want to call \"$h->objectifytext\", perform whatever task that you needed\nthat for, and then call \"$h->deobjectifytext\" before calling anything like \"$h->astext\".\n\ndeobjectifytext\n$h->deobjectifytext();\n\nThis undoes the effect of \"$h->objectifytext\". That is, it takes any \"~text\" pseudo-elements in\nthe tree at/under $h, and deletes each one, replacing each with the content of its \"text\"\nattribute.\n\nNote that if $h itself is a \"~text\" pseudo-element, it will be destroyed -- a condition you may\nneed to treat specially in your calling code (since it means you can't very well do anything\nwith $h after that). So that you can detect that condition, if $h is itself a \"~text\"\npseudo-element, then this method returns the value of the \"text\" attribute, which should be a\ndefined value; in all other cases, it returns undef.\n\n(This method assumes that no \"~text\" pseudo-element has any children.)\n\nnumberlists\n$h->numberlists();\n\nFor every UL, OL, DIR, and MENU element at/under $h, this sets a \"bullet\" attribute for every\nchild LI element. For LI children of an OL, the \"bullet\" attribute's value will be something\nlike \"4.\", \"d.\", \"D.\", \"IV.\", or \"iv.\", depending on the OL element's \"type\" attribute. LI\nchildren of a UL, DIR, or MENU get their \"bullet\" attribute set to \"*\". There should be no\nother LIs (i.e., except as children of OL, UL, DIR, or MENU elements), and if there are, they\nare unaffected.\n\nhasinsanelinkage\n$h->hasinsanelinkage\n\nThis method is for testing whether this element or the elements under it have linkage attributes\n(parent and content) whose values are deeply aberrant: if there are undefs in a content list;\nif an element appears in the content lists of more than one element; if the parent attribute of\nan element doesn't match its actual parent; or if an element appears as its own descendant\n(i.e., if there is a cyclicity in the tree).\n\nThis returns empty list (or false, in scalar context) if the subtree's linkage methods are sane;\notherwise it returns two items (or true, in scalar context): the element where the error\noccurred, and a string describing the error.\n\nThis method is provided is mainly for debugging and troubleshooting -- it should be *quite\nimpossible* for any document constructed via HTML::TreeBuilder to parse into a non-sane tree\n(since it's not the content of the tree per se that's in question, but whether the tree in\nmemory was properly constructed); and it *should* be impossible for you to produce an insane\ntree just thru reasonable use of normal documented structure-modifying methods. But if you're\nconstructing your own trees, and your program is going into infinite loops as during calls to",
            "subsections": [
                {
                    "name": "traverse",
                    "content": "\"hasinsanelinkage\" on the tree.\n\nelementclass\n$classname = $h->elementclass();\n\nThis method returns the class which will be used for new elements. It defaults to HTML::Element,\nbut can be overridden by subclassing or esoteric means best left to those will will read the\nsource and then not complain when those esoteric means change. (Just subclass.)\n"
                }
            ]
        },
        "CLASS METHODS": {
            "content": "",
            "subsections": [
                {
                    "name": "UseWeakRefs",
                    "content": "$enabled = HTML::Element->UseWeakRefs;\nHTML::Element->UseWeakRefs( $enabled );\n\nThis method allows you to check whether weak reference support is enabled, and to enable or\ndisable it. For details, see \"Weak References\". $enabled is true if weak references are enabled.\n\nYou should not switch this in the middle of your program, and you probably shouldn't use it at\nall. Existing trees are not affected by this method (until you start modifying nodes in them).\n\nThrows an exception if you attempt to enable weak references and your Perl or Scalar::Util does\nnot support them.\n\nDisabling weak reference support is deprecated.\n"
                }
            ]
        },
        "SUBROUTINES": {
            "content": "",
            "subsections": [
                {
                    "name": "Version",
                    "content": "This subroutine is deprecated. Please use the standard VERSION method (e.g.\n\"HTML::Element->VERSION\") instead.\n\nABORT OK PRUNE PRUNESOFTLY PRUNEUP\nConstants for signalling back to the traverser\n"
                }
            ]
        },
        "BUGS": {
            "content": "* If you want to free the memory associated with a tree built of HTML::Element nodes, and you\nhave disabled weak references, then you will have to delete it explicitly using the \"delete\"\nmethod. See \"Weak References\".\n\n* There's almost nothing to stop you from making a \"tree\" with cyclicities (loops) in it, which\ncould, for example, make the traverse method go into an infinite loop. So don't make\ncyclicities! (If all you're doing is parsing HTML files, and looking at the resulting trees,\nthis will never be a problem for you.)\n\n* There's no way to represent comments or processing directives in a tree with HTML::Elements.\nNot yet, at least.\n\n* There's (currently) nothing to stop you from using an undefined value as a text segment. If\nyou're running under \"perl -w\", however, this may make HTML::Element's code produce a slew of\nwarnings.\n",
            "subsections": []
        },
        "NOTES ON SUBCLASSING": {
            "content": "You are welcome to derive subclasses from HTML::Element, but you should be aware that the code\nin HTML::Element makes certain assumptions about elements (and I'm using \"element\" to mean ONLY\nan object of class HTML::Element, or of a subclass of HTML::Element):\n\n* The value of an element's parent attribute must either be undef or otherwise false, or must\nbe an element.\n\n* The value of an element's content attribute must either be undef or otherwise false, or a\nreference to an (unblessed) array. The array may be empty; but if it has items, they must ALL be\neither mere strings (text segments), or elements.\n\n* The value of an element's tag attribute should, at least, be a string of printable\ncharacters.\n\nMoreover, bear these rules in mind:\n\n* Do not break encapsulation on objects. That is, access their contents only thru $obj->attr or\nmore specific methods.\n\n* You should think twice before completely overriding any of the methods that HTML::Element\nprovides. (Overriding with a method that calls the superclass method is not so bad, though.)\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "HTML::Tree; HTML::TreeBuilder; HTML::AsSubs; HTML::Tagset; and, for the morbidly curious,\nHTML::Element::traverse.\n",
            "subsections": []
        },
        "ACKNOWLEDGEMENTS": {
            "content": "Thanks to Mark-Jason Dominus for a POD suggestion.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Current maintainers:\n\n*   Christopher J. Madsen \"<perl AT cjmweb.net>\"\n\n*   Jeff Fearn \"<jfearn AT cpan.org>\"\n\nOriginal HTML-Tree author:\n\n*   Gisle Aas\n\nFormer maintainers:\n\n*   Sean M. Burke\n\n*   Andy Lester\n\n*   Pete Krawczyk \"<petek AT cpan.org>\"\n\nYou can follow or contribute to HTML-Tree's development at\n<https://github.com/kentfredric/HTML-Tree>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "Copyright 1995-1998 Gisle Aas, 1999-2004 Sean M. Burke, 2005 Andy Lester, 2006 Pete Krawczyk,\n2010 Jeff Fearn, 2012 Christopher J. Madsen.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nThe programs in this library are distributed in the hope that they will be useful, but without\nany warranty; without even the implied warranty of merchantability or fitness for a particular\npurpose.\n",
            "subsections": []
        }
    },
    "summary": "HTML::Element - Class for objects that represent HTML elements",
    "flags": [],
    "examples": [],
    "see_also": []
}