Mojo::DOM::HTML(3)
π Mojo::DOM::HTML β the HTML/XML engine, bestie edition
okay so welcome to the Mojo::DOM::HTML(3) man page π this is the whole entire HTML/XML engine situation and honestly? it ate. let's get into it.
β¨ NAME β¨
Mojo::DOM::HTML β it's an HTML/XML engine. that's the whole vibe. no cap.
πΈ SYNOPSIS πΈ
like, here's the little demo so you can picture it:
use Mojo::DOM::HTML;
# Turn HTML into DOM tree
my $html = Mojo::DOM::HTML->new;
$html->parse('<div><p id="a">Test</p><p id="b">123</p></div>');
my $tree = $html->tree;
see how it just. turns HTML into a DOM tree? iconic behavior. β¨
π¦ DESCRIPTION π¦
Mojo::DOM::HTML is the HTML/XML engine that Mojo::DOM uses β like, it's the muscle behind the whole thing πͺ and it's built on:
- the HTML Living Standard <https://html.spec.whatwg.org>
- and the Extensible Markup Language (XML) 1.0 <https://www.w3.org/TR/xml/>
so yeah. standards-based. classy. we love to see it. π
β FUNCTIONS β
Mojo::DOM::HTML implements these functions, and you can import each one individually if that's your thing:
π§ tag_to_html
my $str = tag_to_html 'div', id => 'foo', 'safe content';
so this one generates an HTML/XML tag and renders it right away, immediately, no waiting around π¨
and here's the tea: it's a significantly faster alternative to tag for template systems that have to generate a lot of tags. like, a lot a lot. so if you're churning out tags by the hundreds, this is your girl. π₯
π ATTRIBUTES π
Mojo::DOM::HTML implements these attributes:
π tree
my $tree = $html->tree;
$html = $html->tree(['root']);
this is the Document Object Model itself, bestie. the whole tree. π³
β οΈ okay real talk, this structure should only be used very carefully β it's very dynamic, which is a cute way of saying it can absolutely bite you if you go poking at it without thinking. be gentle. π
π xml
my $bool = $html->xml;
$html = $html->xml($bool);
flip this on and it disables HTML semantics in the parser and activates case-sensitivity. defaults to auto-detection based on XML declarations, so it usually just figures itself out. main character energy, honestly. β¨
π METHODS π
Mojo::DOM::HTML inherits all the methods from Mojo::Base (freebies, love that π«Ά) and implements these new ones:
π parse
$html = $html->parse('<foo bar="baz">I β₯ Mojolicious!</foo>');
parse an HTML/XML fragment. that's it. that's the method. put a fragment in, the engine handles it. π
πΈ render
my $str = $html->render;
render the DOM back out to HTML/XML. the reverse trip. π¦
π₯ tag
$html = $html->tag('div', id => 'foo', 'safe content');
generate an HTML/XML tag. (and remember β if you're doing this a zillion times in a template system, tag_to_html above is the significantly faster one, iykyk π)
π SEE ALSO π
MojoliciousMojolicious::Guides- <https://mojolicious.org>
that's the whole page, bestie, go forth and parse π§π
sign-off corner: this masterpiece is from perl v5.42.0, dated 2026-07-15, and yes it lives at Mojo::DOM::HTML(3). periodt. π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms