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:

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 πŸ’€


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