HTML::DOMbo(3)
π HTML::DOMbo π
okay so bestie, welcome to HTML::DOMbo β the little module that lets you convert between XML::DOM and {XML/HTML}::Element trees. that's the whole vibe. slay. β¨
πΈ SYNOPSIS πΈ
use HTML::DOMbo;
use HTML::TreeBuilder;
my $tree = HTML::TreeBuilder->new;
$tree->parse_from_file('foo.html');
my $dom_tree = $tree->to_XML_DOM;
# Now you have a DOM element in $dom_tree!
like, look at that. three lines and you're already living your DOM truth. π
π¦ DESCRIPTION π¦
so here's the tea β: this class sneaks a method into HTML::Element called to_XML_DOM, and it also drops two methods into the class XML::DOM::Node β those are to_HTML_Element and to_XML_Element. two-way street, no cap. π«Ά
β¨ to_XML_DOM β¨
ngl, HTML::TreeBuilder is so good at robustly producing parse trees of HTML β like, genuinely iconic. BUT π the trees it makes are built out of HTML::Element objects, not W3C DOM objects. different species bestie.
so if you wanna poke at a TreeBuilder-made parse tree (sitting there in $tree) through a DOM interface, you use HTML::DOMbo and then you call:
my $dom_tree = $tree->to_XML_DOM;
and boom π₯ β that hands you back a new object of the appropriate class (presumably XML::DOM::Element), living inside a new DOM document, with the exact same structure and content as the HTML::TreeBuilder/Element tree you started with.
but wait, there's more. if you want the elements to be instantiated against an existing document object instead of a fresh one, you call this version instead:
my $dom_tree = $tree->to_XML_DOM($existing_dom_document);
iykyk. π
π to_HTML_Element and to_XML_Element π
okay so this module provides two experimental methods (they live in the XML::DOM::Node class, just so we're clear) called to_HTML_Element and to_XML_Element. what they do is clone a DOM node (or a DOM document, or a document fragment, no judgement) as a brand new HTML::Element or XML::Element object. glow-up fr fr. π
heads up tho β to use the to_XML_Element method you need the XML::Element module installed (it comes from the XML::TreeBuilder dist). no module, no method, that's the rule. π
β οΈ now for the chaotic part. this thing can throw a fatal exception. yes, really. π
and it's also possible for it to return a text string instead β that happens if the DOM node you handed it was a text node. and moreover, in list context it may return any number of items, if the source object is a document fragment containing more than one top-level nodeβ¦ or, like, no nodes at all. it's giving unpredictable queen. π
the author literally wants you to report any problems (or successes!) in using this method. and yes, the behavior of this method may change in response to your requests. so speak up bestie, your voice matters. π£
π SEE ALSO π
XML::DOMHTML::TreeBuilderHTML::ElementXML::Element
go read those too, they're the supporting cast and they ate. π
π COPYRIGHT π
Copyright 2000 Sean M. Burke.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π AUTHOR π
Sean M. Burke, <sburke@cpan.org>
and that's the whole page bestie!! π this was HTML::DOMbo(3) from perl v5.42.0, dated 2025-07-25 β thanks for reading, mwah, go build some trees ππ¦β¨
π¦ where this page comes from
- fedora 43: perl-HTML-DOMbo 3.10-49.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms