HTML5-DOM
view release on metacpan or search on metacpan
my $display = $node->getDefaultBoxType;
Get default CSS "display" property for tag (useful for functions like a L<innerText|/innerText>).
my $tree = HTML5::DOM->new
->parse('<div class="red color">red</div><script>alert()</script><b>bbb</b>');
print $tree->at('div')->getDefaultBoxType(); # block
print $tree->at('script')->getDefaultBoxType(); # none
print $tree->at('b')->getDefaultBoxType(); # inline
=head1 HTML5::DOM::Document
DOM node object for document. Inherit all methods from L<HTML5::DOM::Element|/HTML5::DOM::Element>.
=head1 HTML5::DOM::Fragment
DOM node object for fragments. Inherit all methods from L<HTML5::DOM::Element|/HTML5::DOM::Element>.
=head1 HTML5::DOM::Text
DOM node object for text. Inherit all methods from L<HTML5::DOM::Node|/HTML5::DOM::Node>.
=head1 HTML5::DOM::Comment
DOM node object for comments. Inherit all methods from L<HTML5::DOM::Node|/HTML5::DOM::Node>.
=head1 HTML5::DOM::DocType
DOM node object for document type. Inherit all methods from L<HTML5::DOM::Node|/HTML5::DOM::Node>.
=head3 name
my $name = $node->name;
my $node = $node->name($new_name);
Return or change root element name from doctype.
my $tree = HTML5::DOM->new->parse('
<!DOCTYPE svg>
');
# get
print $tree->document->firstChild->name; # svg
# set
$tree->document->firstChild->name('html');
print $tree->document->firstChild->html; # <!DOCTYPE html>
=head3 publicId
my $public_id = $node->publicId;
my $node = $node->publicId($new_public_id);
Return or change public id from doctype.
my $tree = HTML5::DOM->new->parse('
<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
');
# get
print $tree->document->firstChild->publicId; # -//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN
# set
print $tree->document->firstChild->publicId('-//W3C//DTD SVG 1.1//EN');
print $tree->document->firstChild->html; # <!DOCTYPE svg:svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
=head3 systemId
my $system_id = $node->systemId;
my $node = $node->systemId($new_system_id);
Return or change public id from doctype.
my $tree = HTML5::DOM->new->parse('
<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
');
# get
print $tree->document->firstChild->systemId; # http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd
# set
print $tree->document->firstChild->systemId('http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
print $tree->document->firstChild->html; # <!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
=head1 HTML5::DOM::Collection
CSS Parser object
=head3 new
my $collection = HTML5::DOM::Collection->new($nodes);
Creates new collection from C<$nodes> (reference to array with L<HTML5::DOM::Node|/HTML5::DOM::Node>).
=head3 each
$collection->each(sub {...});
$collection->each(sub {...}, @additional_args);
Foreach all nodes in collection. Returns self.
Example:
$collection->each(sub {
my ($node, $index) = @_;
print "FOUND: node[$index] is a '$node'\n";
});
# Also can bypass additional arguments
$collection->each(sub {
my ($node, $index, $title) = @_;
print $title."node[$index] is a '$node'\n";
}, "FOUND: ");
=head3 map
my $new_collection = $collection->map(sub {
my ($token, $index) = @_;
return "FOUND: ".$node->tag." => $index";
});
# Also can bypass additional arguments
my $new_collection = $collection->map(sub {
my ($token, $index, $title) = @_;
return $title.$node->tag." => $index";
}, "FOUND: ");
Apply callback for each node in collection. Returns new array from results.
my $new_collection = $collection->map($method, @args);
Call method for each node in collection. Returns new L<HTML5::DOM::Collection|/HTML5::DOM::Collection> from results.
Example:
# set text 'test!' for all nodes
$collection->map('text', 'test!');
# get all tag names as array
my $new_collection = $collection->map('tag');
( run in 1.833 second using v1.01-cache-2.11-cpan-119454b85a5 )