nodeValue
data
my $value = $node->nodeValue();
my $value = $node->data(); # alias
my $node = $node->nodeValue($new_value);
my $node = $node->data($new_value); # alias
Get or set value of node. Only works for non-element nodes, such as
HTML5::DOM::Element, HTML5::DOM::Element, HTML5::DOM::Element. Return
"undef" for other.
my $tree = HTML5::DOM->new->parse('');
my $comment = $tree->createComment("comment text");
print $comment->nodeValue; # comment text
$comment->nodeValue(' new comment text ');
print $comment->html; #
isConnected
my $flag = $node->isConnected;
Return true, if node has parent.
my $tree = HTML5::DOM->new->parse('
');
print $tree->at('#test')->isConnected; # 1
print $tree->createElement("div")->isConnected; # 0
parent
parentElement
my $node = $node->parent;
my $node = $node->parentElement; # alias
Return parent node. Return "undef", if node detached.
my $tree = HTML5::DOM->new->parse('
');
print $tree->at('#test')->parent->tag; # body
document
ownerDocument
my $doc = $node->document;
my $doc = $node->ownerDocument; # alias
Return parent HTML5::DOM::Document.
my $tree = HTML5::DOM->new->parse('
');
print ref($tree->at('#test')->document); # HTML5::DOM::Document
append
appendChild
my $node = $node->append($child);
my $child = $node->appendChild($child); # alias
Append node to child nodes.
append - returned value is the self node, for chain calls
appendChild - returned value is the appended child except when the given
child is a HTML5::DOM::Fragment, in which case the empty
HTML5::DOM::Fragment is returned.
my $tree = HTML5::DOM->new->parse('
some bold text
');
$tree->at('div')
->append($tree->createElement('br'))
->append($tree->createElement('br'));
print $tree->at('div')->html; #
some bold text
prepend
prependChild
my $node = $node->prepend($child);
my $child = $node->prependChild($child); # alias
Prepend node to child nodes.
prepend - returned value is the self node, for chain calls
prependChild - returned value is the prepended child except when the
given child is a HTML5::DOM::Fragment, in which case the empty
HTML5::DOM::Fragment is returned.
my $tree = HTML5::DOM->new->parse('
some bold text
');
$tree->at('div')
->prepend($tree->createElement('br'))
->prepend($tree->createElement('br'));
print $tree->at('div')->html; #
some bold text
replace
replaceChild
my $old_node = $old_node->replace($new_node);
my $old_node = $old_node->parent->replaceChild($new_node, $old_node); # alias
Replace node in parent child nodes.
my $tree = HTML5::DOM->new->parse('
some bold text
');
my $old = $tree->at('b')->replace($tree->createElement('br'));
print $old->html; #
bold
print $tree->at('div')->html; #
some text
before
insertBefore
my $node = $node->before($new_node);
my $new_node = $node->parent->insertBefore($new_node, $node); # alias
Insert new node before current node.
before - returned value is the self node, for chain calls
insertBefore - returned value is the added child except when the given
child is a HTML5::DOM::Fragment, in which case the empty
HTML5::DOM::Fragment is returned.
my $tree = HTML5::DOM->new->parse('
some bold text
');
$tree->at('b')->before($tree->createElement('br'));
print $tree->at('div')->html; #
some bold text
after
insertAfter
my $node = $node->after($new_node);
my $new_node = $node->parent->insertAfter($new_node, $node); # alias
Insert new node after current node.
after - returned value is the self node, for chain calls
insertAfter - returned value is the added child except when the given
child is a HTML5::DOM::Fragment, in which case the empty
HTML5::DOM::Fragment is returned.
my $tree = HTML5::DOM->new->parse('
some bold text
');
$tree->at('b')->after($tree->createElement('br'));
print $tree->at('div')->html; #
some bold text
remove
removeChild
my $node = $node->remove;
my $node = $node->parent->removeChild($node); # alias
Remove node from parent. Return removed node.
my $tree = HTML5::DOM->new->parse('
some bold text
');
print $tree->at('b')->remove->html; #
bold
print $tree->at('div')->html; #
some text
clone
cloneNode
# clone node to current tree
my $node = $node->clone($deep = 0);
my $node = $node->cloneNode($deep = 0); # alias
# clone node to foreign tree
my $node = $node->clone($deep, $new_tree);
my $node = $node->cloneNode($deep, $new_tree); # alias
Clone node.
deep = 0 - only specified node, without childs.
deep = 1 - deep copy with all child nodes.
new_tree - destination tree (if need copy to foreign tree)
my $tree = HTML5::DOM->new->parse('
some bold text
');
print $tree->at('b')->clone(0)->html; #
print $tree->at('b')->clone(1)->html; #
bold
void
my $flag = $node->void;
Return true if node is void. For more details:
print $tree->createElement('br')->void; # 1
selfClosed
my $flag = $node->selfClosed;
Return true if node self closed.
print $tree->createElement('br')->selfClosed; # 1
position
my $position = $node->position;
Return offsets in input buffer.
print Dumper($node->position);
# $VAR1 = {'raw_length' => 3, 'raw_begin' => 144, 'element_begin' => 143, 'element_length' => 5}
isSameNode
my $flag = $node->isSameNode($other_node);
Tests whether two nodes are the same, that is if they reference the same
object.
my $tree = HTML5::DOM->new->parse('
');
my $li = $tree->find('li');
print $li->[0]->isSameNode($li->[0]); # 1
print $li->[0]->isSameNode($li->[1]); # 0
print $li->[0]->isSameNode($li->[2]); # 0
wait
my $parser = HTML5::DOM->new({async => 1});
my $tree = $parser->parse($some_big_html_file);
# ...some your work...
$tree->body->wait; # wait before parsing for is done
Blocking wait for node parsing done. Only for async mode.
parsed
my $parser = HTML5::DOM->new({async => 1});
my $tree = $parser->parse($some_big_html_file);
# ...some your work...
while (!$tree->body->parsed); # wait before parsing for is done
Non-blocking way for check if node parsing done. Only for async mode.
HTML5::DOM::Element
DOM node object for elements. Inherit all methods from HTML5::DOM::Node.
children
my $collection = $node->children;
Returns all child elements of current node in HTML5::DOM::Collection.
my $tree = HTML5::DOM->new->parse('
');
my $collection = $tree->at('ul')->children;
print $collection->[0]->html; # Perl
print $collection->[1]->html; # PHP
print $collection->[2]->html; # C++
childrenNode
childNodes
my $collection = $node->childrenNode;
my $collection = $node->childNodes; # alias
Returns all child nodes of current node in HTML5::DOM::Collection.
my $tree = HTML5::DOM->new->parse('
');
my $collection = $tree->at('ul')->childrenNode;
print $collection->[0]->html; # Perl
print $collection->[1]->html; #
print $collection->[2]->html; # PHP
print $collection->[3]->html; # C++
attr
removeAttr
Universal attributes accessor, for single human-friendly api.
# attribute get
my $value = $node->attr($key);
# attribute set
my $node = $node->attr($key, $value);
my $node = $node->attr($key => $value);
# attribute remove
my $node = $node->attr($key, undef);
my $node = $node->attr($key => undef);
my $node = $node->removeAttr($key);
# bulk attributes set
my $node = $node->attr({$key => $value, $key2 => $value2});
# bulk attributes remove
my $node = $node->attr({$key => undef, $key2 => undef});
# bulk get all attributes in hash
my $hash = $node->attr;
Example:
my $tree = HTML5::DOM->new->parse('
');
my $div = $tree->at('ul');
$div->attr("data-new", "test");
print $div->attr("data-test"); # test value
print $div->{"data-test"}; # test value
print $div->attr->{"data-test"}; # test value
# {id => "test", "data-test" => "test value", "data-href" => "#", "data-new" => "test"}
print $div->attr;
$div->removeAttr("data-test");
# {id => "test", "data-href" => "#", "data-new" => "test"}
print $div->attr;
getAttribute
my $value = $node->getAttribute($key);
my $value = $node->attr($key); # alias
Get attribute value by key.
setAttribute
my $node = $node->setAttribute($key, $value);
my $node = $node->attr($key, $value); # alias
Set new value or create new attibute.
removeAttribute
my $node = $node->removeAttribute($key);
my $node = $node->removeAttr($key); # alias
Remove attribute.
className
my $classes = $node->className;
# alias for
my $classes = $node->attr("class");
classList
my $class_list = $node->classList;
# has class
my $flag = $class_list->has($class_name);
my $flag = $class_list->contains($class_name);
# add class
my $class_list = $class_list->add($class_name);
my $class_list = $class_list->add($class_name, $class_name1, $class_name2, ...);
# add class
my $class_list = $class_list->remove($class_name);
my $class_list = $class_list->remove($class_name, $class_name1, $class_name2, ...);
# toggle class
my $state = $class_list->toggle($class_name);
my $state = $class_list->toggle($class_name, $force_state);
Manipulations with classes. Returns HTML5::DOM::TokenList.
Similar to
my $tree = HTML5::DOM->new->parse('red
')
my $node = $tree->body->at('.red');
print $node->has('red'); # 1
print $node->has('blue'); # 0
$node->add('blue', 'red', 'yellow', 'orange');
print $node->className; # red blue yellow orange
$node->remove('blue', 'orange');
print $node->className; # red yellow
print $node->toggle('blue'); # 1
print $node->className; # red yellow blue
print $node->toggle('blue'); # 0
print $node->className; # red yellow
at
querySelector
my $node = $node->at($selector);
my $node = $node->at($selector, $combinator);
my $node = $node->querySelector($selector); # alias
my $node = $node->querySelector($selector, $combinator); # alias
Find one element node in current node descendants using CSS Selectors
Level 4
Return node, or "undef" if not find.
* $selector - selector query as plain text or precompiled as
HTML5::DOM::CSS::Selector or HTML5::DOM::CSS::Selector.
* $combinator - custom selector combinator, applies to current node
* ">>" - descendant selector (default)
* ">" - child selector
* "+" - adjacent sibling selector
* "~" - general sibling selector
* "||" - column combinator
my $tree = HTML5::DOM->new->parse('red
blue
')
my $node = $tree->body->at('body > div.red');
print $node->html; # red
find
querySelectorAll
my $collection = $node->find($selector);
my $collection = $node->find($selector, $combinator);
my $collection = $node->querySelectorAll($selector); # alias
my $collection = $node->querySelectorAll($selector, $combinator); # alias
Find all element nodes in current node descendants using CSS Selectors
Level 4
Return HTML5::DOM::Collection.
* $selector - selector query as plain text or precompiled as
HTML5::DOM::CSS::Selector or HTML5::DOM::CSS::Selector.
* $combinator - custom selector combinator, applies to current node
* ">>" - descendant selector (default)
* ">" - child selector
* "+" - adjacent sibling selector
* "~" - general sibling selector
* "||" - column combinator
my $tree = HTML5::DOM->new->parse('red
blue
')
my $collection = $tree->body->at('body > div.red, body > div.blue');
print $collection->[0]->html; # red
print $collection->[1]->html; # blue
findId
getElementById
my $node = $node->findId($tag);
my $node = $node->getElementById($tag); # alias
Find element node with specified id in current node descendants.
Return HTML5::DOM::Node or "undef".
my $tree = HTML5::DOM->new->parse('red
blue
')
my $node = $tree->body->findId('test');
print $node->html; # blue
findTag
getElementsByTagName
my $node = $node->findTag($tag);
my $node = $node->getElementsByTagName($tag); # alias
Find all element nodes in current node descendants with specified tag
name.
Return HTML5::DOM::Collection.
my $tree = HTML5::DOM->new->parse('red
blue
')
my $collection = $tree->body->findTag('div');
print $collection->[0]->html; # red
print $collection->[1]->html; # blue
findClass
getElementsByClassName
my $collection = $node->findClass($class);
my $collection = $node->getElementsByClassName($class); # alias
Find all element nodes in current node descendants with specified class
name. This is more fast equivalent to [class~="value"] selector.
Return HTML5::DOM::Collection.
my $tree = HTML5::DOM->new
->parse('red
blue
');
my $collection = $tree->body->findClass('color');
print $collection->[0]->html; # red
print $collection->[1]->html; # blue
findAttr
getElementByAttribute
# Find all elements with attribute
my $collection = $node->findAttr($attribute);
my $collection = $node->getElementByAttribute($attribute); # alias
# Find all elements with attribute and mathcing value
my $collection = $node->findAttr($attribute, $value, $case = 0, $cmp = '=');
my $collection = $node->getElementByAttribute($attribute, $value, $case = 0, $cmp = '='); # alias
Find all element nodes in tree with specified attribute and optional
matching value.
Return HTML5::DOM::Collection.
my $tree = HTML5::DOM->new
->parse('red
blue
');
my $collection = $tree->body->findAttr('class', 'CoLoR', 1, '~');
print $collection->[0]->html; # red
print $collection->[1]->html; # blue
CSS selector analogs:
# [$attribute=$value]
my $collection = $node->findAttr($attribute, $value, 0, '=');
# [$attribute=$value i]
my $collection = $node->findAttr($attribute, $value, 1, '=');
# [$attribute~=$value]
my $collection = $node->findAttr($attribute, $value, 0, '~');
# [$attribute|=$value]
my $collection = $node->findAttr($attribute, $value, 0, '|');
# [$attribute*=$value]
my $collection = $node->findAttr($attribute, $value, 0, '*');
# [$attribute^=$value]
my $collection = $node->findAttr($attribute, $value, 0, '^');
# [$attribute$=$value]
my $collection = $node->findAttr($attribute, $value, 0, '$');
getDefaultBoxType
my $display = $node->getDefaultBoxType;
Get default CSS "display" property for tag (useful for functions like a
innerText).
my $tree = HTML5::DOM->new
->parse('red
bbb ');
print $tree->at('div')->getDefaultBoxType(); # block
print $tree->at('script')->getDefaultBoxType(); # none
print $tree->at('b')->getDefaultBoxType(); # inline
HTML5::DOM::Document
DOM node object for document. Inherit all methods from
HTML5::DOM::Element.
HTML5::DOM::Fragment
DOM node object for fragments. Inherit all methods from
HTML5::DOM::Element.
HTML5::DOM::Text
DOM node object for text. Inherit all methods from HTML5::DOM::Node.
HTML5::DOM::Comment
DOM node object for comments. Inherit all methods from HTML5::DOM::Node.
HTML5::DOM::DocType
DOM node object for document type. Inherit all methods from
HTML5::DOM::Node.
HTML5::DOM::Collection
CSS Parser object
new
my $collection = HTML5::DOM::Collection->new($nodes);
Creates new collection from $nodes (reference to array with
HTML5::DOM::Node).
each
my $collection = $collection->each(sub {
my ($node, $index) = @_;
print "node[$index] is a '$node'\n";
});
Forach all nodes in collection.
map
my $result = $collection->map(sub {
my ($token, $index) = @_;
return $node->tag." => $index";
});
Apply callback for each node in collection. Returns new array from
results.
my $result = $collection->map($method, @args);
Call method for each node in collection. Returns new
HTML5::DOM::Collection from results.
Example:
# set text 'test!' for all nodes
my $result = $collection->map('text', 'test!');
# get all tag names as array
my $result = $collection->map('tag');
# remove all nodes in collection
$collection->map('remove');
add
my $collection = $collection->add($node);
Add new item to collection.
length
my $length = $collection->length;
Items count in collection.
my $tree = HTML5::DOM->new->parse('
');
my $collection = $tree->find('ul li');
print $collection->length; # 3
first
last
my $node = $collection->first;
my $node = $collection->last;
Get first or last item in collection.
my $tree = HTML5::DOM->new->parse('
');
my $collection = $tree->find('ul li');
print $collection->first->html; # Linux
print $collection->last->html; # Windows
item
my $node = $collection->item($index);
my $node = $collection->[$index];
Get item by $index in collection.
my $tree = HTML5::DOM->new->parse('
');
my $collection = $tree->find('ul li');
print $collection->item(1)->html; # OSX
print $collection->[1]->html; # OSX
array
my $node = $collection->array();
Get collection items as array.
html
my $html = $collection->html;
Concat from all items.
text
my $text = $collection->text;
Concat from all items.
HTML5::DOM::TokenList
Similar to
has
contains
my $flag = $tokens->has($token);
my $flag = $tokens->contains($token); # alias
Check if token contains in current tokens list.
add
my $tokens = $tokens->add($token);
my $tokens = $tokens->add($token, $token2, ...);
Add new token (or tokens) to current tokens list. Returns self.
remove
my $tokens = $tokens->add($token);
my $tokens = $tokens->add($token, $token2, ...);
Remove one or more tokens from current tokens list. Returns self.
toggle
my $state = $tokens->toggle($token);
my $state = $tokens->toggle($token, $force_state);
* $token - specified token name
* $force_state - optional force state.
If 1 - similar to add
If 0 - similar to remove
Toggle specified token in current tokens list.
* If token exists - remove it
* If token not exists - add it
length
my $length = $tokens->length;
Returns tokens count in current list.
item
my $token = $tokens->item($index);
my $token = $tokens->[$index];
Return token by index.
each
my $token = $tokens->each(sub {
my ($token, $index) = @_;
print "tokens[$index] is a '$token'\n";
});
Forach all tokens in list.
HTML5::DOM::CSS
CSS Parser object
new
my $css = HTML5::DOM::CSS->new;
Create new css parser object.
parseSelector
my $selector = HTML5::DOM::CSS->parseSelector($selector_text);
Parse $selector_text and return HTML5::DOM::CSS::Selector.
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('body div.red, body span.blue');
HTML5::DOM::CSS::Selector
CSS Selector object (precompiled selector)
new
my $selector = HTML5::DOM::CSS::Selector->new($selector_text);
Parse $selector_text and create new css selector object. If your need
parse many selectors, more efficient way using single instance of parser
HTML5::DOM::CSS and parseSelector method.
text
my $selector_text = $selector->text;
Serialize selector to text.
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('body div.red, body span.blue');
print $selector->text."\n"; # body div.red, body span.blue
ast
my $ast = $entry->ast;
Serialize selector to very simple AST format.
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('div > .red');
print Dumper($selector->ast);
# $VAR1 = [[
# {
# 'value' => 'div',
# 'type' => 'tag'
# },
# {
# 'type' => 'combinator',
# 'value' => 'child'
# },
# {
# 'type' => 'class',
# 'value' => 'red'
# }
# ]];
length
my $length = $selector->length;
Get selector entries count (selectors separated by "," combinator)
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('body div.red, body span.blue');
print $selector->length."\n"; # 2
entry
my $entry = $selector->entry($index);
Get selector entry by $index end return
HTML5::DOM::CSS::Selector::Entry.
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('body div.red, body span.blue');
print $selector->entry(0)->text."\n"; # body div.red
print $selector->entry(1)->text."\n"; # body span.blue
HTML5::DOM::CSS::Selector::Entry
CSS selector entry object (precompiled selector)
text
my $selector_text = $entry->text;
Serialize entry to text.
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('body div.red, body span.blue');
my $entry = $selector->entry(0);
print $entry->text."\n"; # body div.red
pseudoElement
my $pseudo_name = $entry->pseudoElement;
Return pseudo-element name for entry.
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('div::after');
my $entry = $selector->entry(0);
print $entry->pseudoElement."\n"; # after
ast
my $ast = $entry->ast;
Serialize entry to very simple AST format.
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('div > .red');
my $entry = $selector->entry(0);
print Dumper($entry->ast);
# $VAR1 = [
# {
# 'value' => 'div',
# 'type' => 'tag'
# },
# {
# 'type' => 'combinator',
# 'value' => 'child'
# },
# {
# 'type' => 'class',
# 'value' => 'red'
# }
# ];
specificity
my $specificity = $entry->specificity;
Get specificity in hash "{a, b, c}"
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('body div.red, body span.blue');
my $entry = $selector->entry(0);
print Dumper($entry->specificity); # {b => 0, a => 1, c => 2}
specificityArray
my $specificity = $entry->specificityArray;
Get specificity in array "[b, a, c]" (ordered by weight)
my $css = HTML5::DOM::CSS->new;
my $selector = $css->parseSelector('body div.red, body span.blue');
my $entry = $selector->entry(0);
print Dumper($entry->specificityArray); # [0, 1, 2]
HTML5::DOM::Encoding
Encoding detection.
See for available encodings: "ENCODINGS"
id2name
my $encoding = HTML5::DOM::Encoding::id2name($encoding_id);
Get encoding name by id.
print HTML5::DOM::Encoding::id2name(HTML5::DOM::Encoding->UTF_8); # UTF-8
name2id
my $encoding_id = HTML5::DOM::Encoding::name2id($encoding);
Get id by name.
print HTML5::DOM::Encoding->UTF_8; # 0
print HTML5::DOM::Encoding::id2name("UTF-8"); # 0
detectAuto
my ($encoding_id, $new_text) = HTML5::DOM::Encoding::detectAuto($text, $max_length = 0);
Auto detect text encoding using (in this order):
* detectByPrescanStream
* detectBomAndCut
* detect
Returns array with encoding id and new text without BOM, if success.
If fail, then encoding id equal HTML5::DOM::Encoding->NOT_DETERMINED.
my ($encoding_id, $new_text) = HTML5::DOM::Encoding::detectAuto("ололо");
my $encoding = HTML5::DOM::Encoding::id2name($encoding_id);
print $encoding; # UTF-8
detect
my $encoding_id = HTML5::DOM::Encoding::detect($text, $max_length = 0);
Detect text encoding. Single method for both detectRussian and
detectUnicode.
Returns encoding id, if success. And returns
HTML5::DOM::Encoding->NOT_DETERMINED if fail.
my $encoding_id = HTML5::DOM::Encoding::detect("ололо");
my $encoding = HTML5::DOM::Encoding::id2name($encoding_id);
print $encoding; # UTF-8
detectRussian
my $encoding_id = HTML5::DOM::Encoding::detectRussian($text, $max_length = 0);
Detect russian text encoding (using lowercase trigrams), such as
"windows-1251", "koi8-r", "iso-8859-5", "x-mac-cyrillic", "ibm866".
Returns encoding id, if success. And returns
HTML5::DOM::Encoding->NOT_DETERMINED if fail.
detectUnicode
my $encoding_id = HTML5::DOM::Encoding::detectRussian($text, $max_length = 0);
Detect unicode family text encoding, such as "UTF-8", "UTF-16LE",
"UTF-16BE".
Returns encoding id, if success. And returns
HTML5::DOM::Encoding->NOT_DETERMINED if fail.
# get UTF-16LE data for test
my $str = "ололо";
Encode::from_to($str, "UTF-8", "UTF-16LE");
my $encoding_id = HTML5::DOM::Encoding::detectUnicode($str);
my $encoding = HTML5::DOM::Encoding::id2name($encoding_id);
print $encoding; # UTF-16LE
detectByPrescanStream
my $encoding_id = HTML5::DOM::Encoding::detectByPrescanStream($text, $max_length = 0);
Detect encoding by parsing " " tags in html.
Returns encoding id, if success. And returns
HTML5::DOM::Encoding->NOT_DETERMINED if fail.
See for more info:
my $encoding_id = HTML5::DOM::Encoding::detectByPrescanStream('
');
my $encoding = HTML5::DOM::Encoding::id2name($encoding_id);
print $encoding; # WINDOWS-1251
detectByCharset
my $encoding_id = HTML5::DOM::Encoding::detectByCharset($text, $max_length = 0);
Extracting character encoding from string. Find "charset=" and see
encoding. Return found raw data.
For example: "text/html; charset=windows-1251". Return
HTML5::DOM::Encoding->WINDOWS_1251
And returns HTML5::DOM::Encoding->NOT_DETERMINED if fail.
See for more info:
my $encoding_id = HTML5::DOM::Encoding::detectByPrescanStream('
');
my $encoding = HTML5::DOM::Encoding::id2name($encoding_id);
print $encoding; # WINDOWS-1251
detectBomAndCut
my ($encoding_id, $new_text) = HTML5::DOM::Encoding::detectBomAndCut($text, $max_length = 0);
Returns array with encoding id and new text without BOM.
If fail, then encoding id equal HTML5::DOM::Encoding->NOT_DETERMINED.
my ($encoding_id, $new_text) = HTML5::DOM::Encoding::detectBomAndCut("\xEF\xBB\xBFололо");
my $encoding = HTML5::DOM::Encoding::id2name($encoding_id);
print $encoding; # UTF-8
print $new_text; # ололо
NAMESPACES
Supported namespace names
html, matml, svg, xlink, xml, xmlns
Supported namespace id constants
HTML5::DOM->NS_UNDEF
HTML5::DOM->NS_HTML
HTML5::DOM->NS_MATHML
HTML5::DOM->NS_SVG
HTML5::DOM->NS_XLINK
HTML5::DOM->NS_XML
HTML5::DOM->NS_XMLNS
HTML5::DOM->NS_ANY
HTML5::DOM->NS_LAST_ENTRY
TAGS
HTML5::DOM->TAG__UNDEF
HTML5::DOM->TAG__TEXT
HTML5::DOM->TAG__COMMENT
HTML5::DOM->TAG__DOCTYPE
HTML5::DOM->TAG_A
HTML5::DOM->TAG_ABBR
HTML5::DOM->TAG_ACRONYM
HTML5::DOM->TAG_ADDRESS
HTML5::DOM->TAG_ANNOTATION_XML
HTML5::DOM->TAG_APPLET
HTML5::DOM->TAG_AREA
HTML5::DOM->TAG_ARTICLE
HTML5::DOM->TAG_ASIDE
HTML5::DOM->TAG_AUDIO
HTML5::DOM->TAG_B
HTML5::DOM->TAG_BASE
HTML5::DOM->TAG_BASEFONT
HTML5::DOM->TAG_BDI
HTML5::DOM->TAG_BDO
HTML5::DOM->TAG_BGSOUND
HTML5::DOM->TAG_BIG
HTML5::DOM->TAG_BLINK
HTML5::DOM->TAG_BLOCKQUOTE
HTML5::DOM->TAG_BODY
HTML5::DOM->TAG_BR
HTML5::DOM->TAG_BUTTON
HTML5::DOM->TAG_CANVAS
HTML5::DOM->TAG_CAPTION
HTML5::DOM->TAG_CENTER
HTML5::DOM->TAG_CITE
HTML5::DOM->TAG_CODE
HTML5::DOM->TAG_COL
HTML5::DOM->TAG_COLGROUP
HTML5::DOM->TAG_COMMAND
HTML5::DOM->TAG_COMMENT
HTML5::DOM->TAG_DATALIST
HTML5::DOM->TAG_DD
HTML5::DOM->TAG_DEL
HTML5::DOM->TAG_DETAILS
HTML5::DOM->TAG_DFN
HTML5::DOM->TAG_DIALOG
HTML5::DOM->TAG_DIR
HTML5::DOM->TAG_DIV
HTML5::DOM->TAG_DL
HTML5::DOM->TAG_DT
HTML5::DOM->TAG_EM
HTML5::DOM->TAG_EMBED
HTML5::DOM->TAG_FIELDSET
HTML5::DOM->TAG_FIGCAPTION
HTML5::DOM->TAG_FIGURE
HTML5::DOM->TAG_FONT
HTML5::DOM->TAG_FOOTER
HTML5::DOM->TAG_FORM
HTML5::DOM->TAG_FRAME
HTML5::DOM->TAG_FRAMESET
HTML5::DOM->TAG_H1
HTML5::DOM->TAG_H2
HTML5::DOM->TAG_H3
HTML5::DOM->TAG_H4
HTML5::DOM->TAG_H5
HTML5::DOM->TAG_H6
HTML5::DOM->TAG_HEAD
HTML5::DOM->TAG_HEADER
HTML5::DOM->TAG_HGROUP
HTML5::DOM->TAG_HR
HTML5::DOM->TAG_HTML
HTML5::DOM->TAG_I
HTML5::DOM->TAG_IFRAME
HTML5::DOM->TAG_IMAGE
HTML5::DOM->TAG_IMG
HTML5::DOM->TAG_INPUT
HTML5::DOM->TAG_INS
HTML5::DOM->TAG_ISINDEX
HTML5::DOM->TAG_KBD
HTML5::DOM->TAG_KEYGEN
HTML5::DOM->TAG_LABEL
HTML5::DOM->TAG_LEGEND
HTML5::DOM->TAG_LI
HTML5::DOM->TAG_LINK
HTML5::DOM->TAG_LISTING
HTML5::DOM->TAG_MAIN
HTML5::DOM->TAG_MAP
HTML5::DOM->TAG_MARK
HTML5::DOM->TAG_MARQUEE
HTML5::DOM->TAG_MENU
HTML5::DOM->TAG_MENUITEM
HTML5::DOM->TAG_META
HTML5::DOM->TAG_METER
HTML5::DOM->TAG_MTEXT
HTML5::DOM->TAG_NAV
HTML5::DOM->TAG_NOBR
HTML5::DOM->TAG_NOEMBED
HTML5::DOM->TAG_NOFRAMES
HTML5::DOM->TAG_NOSCRIPT
HTML5::DOM->TAG_OBJECT
HTML5::DOM->TAG_OL
HTML5::DOM->TAG_OPTGROUP
HTML5::DOM->TAG_OPTION
HTML5::DOM->TAG_OUTPUT
HTML5::DOM->TAG_P
HTML5::DOM->TAG_PARAM
HTML5::DOM->TAG_PLAINTEXT
HTML5::DOM->TAG_PRE
HTML5::DOM->TAG_PROGRESS
HTML5::DOM->TAG_Q
HTML5::DOM->TAG_RB
HTML5::DOM->TAG_RP
HTML5::DOM->TAG_RT
HTML5::DOM->TAG_RTC
HTML5::DOM->TAG_RUBY
HTML5::DOM->TAG_S
HTML5::DOM->TAG_SAMP
HTML5::DOM->TAG_SCRIPT
HTML5::DOM->TAG_SECTION
HTML5::DOM->TAG_SELECT
HTML5::DOM->TAG_SMALL
HTML5::DOM->TAG_SOURCE
HTML5::DOM->TAG_SPAN
HTML5::DOM->TAG_STRIKE
HTML5::DOM->TAG_STRONG
HTML5::DOM->TAG_STYLE
HTML5::DOM->TAG_SUB
HTML5::DOM->TAG_SUMMARY
HTML5::DOM->TAG_SUP
HTML5::DOM->TAG_SVG
HTML5::DOM->TAG_TABLE
HTML5::DOM->TAG_TBODY
HTML5::DOM->TAG_TD
HTML5::DOM->TAG_TEMPLATE
HTML5::DOM->TAG_TEXTAREA
HTML5::DOM->TAG_TFOOT
HTML5::DOM->TAG_TH
HTML5::DOM->TAG_THEAD
HTML5::DOM->TAG_TIME
HTML5::DOM->TAG_TITLE
HTML5::DOM->TAG_TR
HTML5::DOM->TAG_TRACK
HTML5::DOM->TAG_TT
HTML5::DOM->TAG_U
HTML5::DOM->TAG_UL
HTML5::DOM->TAG_VAR
HTML5::DOM->TAG_VIDEO
HTML5::DOM->TAG_WBR
HTML5::DOM->TAG_XMP
HTML5::DOM->TAG_ALTGLYPH
HTML5::DOM->TAG_ALTGLYPHDEF
HTML5::DOM->TAG_ALTGLYPHITEM
HTML5::DOM->TAG_ANIMATE
HTML5::DOM->TAG_ANIMATECOLOR
HTML5::DOM->TAG_ANIMATEMOTION
HTML5::DOM->TAG_ANIMATETRANSFORM
HTML5::DOM->TAG_CIRCLE
HTML5::DOM->TAG_CLIPPATH
HTML5::DOM->TAG_COLOR_PROFILE
HTML5::DOM->TAG_CURSOR
HTML5::DOM->TAG_DEFS
HTML5::DOM->TAG_DESC
HTML5::DOM->TAG_ELLIPSE
HTML5::DOM->TAG_FEBLEND
HTML5::DOM->TAG_FECOLORMATRIX
HTML5::DOM->TAG_FECOMPONENTTRANSFER
HTML5::DOM->TAG_FECOMPOSITE
HTML5::DOM->TAG_FECONVOLVEMATRIX
HTML5::DOM->TAG_FEDIFFUSELIGHTING
HTML5::DOM->TAG_FEDISPLACEMENTMAP
HTML5::DOM->TAG_FEDISTANTLIGHT
HTML5::DOM->TAG_FEDROPSHADOW
HTML5::DOM->TAG_FEFLOOD
HTML5::DOM->TAG_FEFUNCA
HTML5::DOM->TAG_FEFUNCB
HTML5::DOM->TAG_FEFUNCG
HTML5::DOM->TAG_FEFUNCR
HTML5::DOM->TAG_FEGAUSSIANBLUR
HTML5::DOM->TAG_FEIMAGE
HTML5::DOM->TAG_FEMERGE
HTML5::DOM->TAG_FEMERGENODE
HTML5::DOM->TAG_FEMORPHOLOGY
HTML5::DOM->TAG_FEOFFSET
HTML5::DOM->TAG_FEPOINTLIGHT
HTML5::DOM->TAG_FESPECULARLIGHTING
HTML5::DOM->TAG_FESPOTLIGHT
HTML5::DOM->TAG_FETILE
HTML5::DOM->TAG_FETURBULENCE
HTML5::DOM->TAG_FILTER
HTML5::DOM->TAG_FONT_FACE
HTML5::DOM->TAG_FONT_FACE_FORMAT
HTML5::DOM->TAG_FONT_FACE_NAME
HTML5::DOM->TAG_FONT_FACE_SRC
HTML5::DOM->TAG_FONT_FACE_URI
HTML5::DOM->TAG_FOREIGNOBJECT
HTML5::DOM->TAG_G
HTML5::DOM->TAG_GLYPH
HTML5::DOM->TAG_GLYPHREF
HTML5::DOM->TAG_HKERN
HTML5::DOM->TAG_LINE
HTML5::DOM->TAG_LINEARGRADIENT
HTML5::DOM->TAG_MARKER
HTML5::DOM->TAG_MASK
HTML5::DOM->TAG_METADATA
HTML5::DOM->TAG_MISSING_GLYPH
HTML5::DOM->TAG_MPATH
HTML5::DOM->TAG_PATH
HTML5::DOM->TAG_PATTERN
HTML5::DOM->TAG_POLYGON
HTML5::DOM->TAG_POLYLINE
HTML5::DOM->TAG_RADIALGRADIENT
HTML5::DOM->TAG_RECT
HTML5::DOM->TAG_SET
HTML5::DOM->TAG_STOP
HTML5::DOM->TAG_SWITCH
HTML5::DOM->TAG_SYMBOL
HTML5::DOM->TAG_TEXT
HTML5::DOM->TAG_TEXTPATH
HTML5::DOM->TAG_TREF
HTML5::DOM->TAG_TSPAN
HTML5::DOM->TAG_USE
HTML5::DOM->TAG_VIEW
HTML5::DOM->TAG_VKERN
HTML5::DOM->TAG_MATH
HTML5::DOM->TAG_MACTION
HTML5::DOM->TAG_MALIGNGROUP
HTML5::DOM->TAG_MALIGNMARK
HTML5::DOM->TAG_MENCLOSE
HTML5::DOM->TAG_MERROR
HTML5::DOM->TAG_MFENCED
HTML5::DOM->TAG_MFRAC
HTML5::DOM->TAG_MGLYPH
HTML5::DOM->TAG_MI
HTML5::DOM->TAG_MLABELEDTR
HTML5::DOM->TAG_MLONGDIV
HTML5::DOM->TAG_MMULTISCRIPTS
HTML5::DOM->TAG_MN
HTML5::DOM->TAG_MO
HTML5::DOM->TAG_MOVER
HTML5::DOM->TAG_MPADDED
HTML5::DOM->TAG_MPHANTOM
HTML5::DOM->TAG_MROOT
HTML5::DOM->TAG_MROW
HTML5::DOM->TAG_MS
HTML5::DOM->TAG_MSCARRIES
HTML5::DOM->TAG_MSCARRY
HTML5::DOM->TAG_MSGROUP
HTML5::DOM->TAG_MSLINE
HTML5::DOM->TAG_MSPACE
HTML5::DOM->TAG_MSQRT
HTML5::DOM->TAG_MSROW
HTML5::DOM->TAG_MSTACK
HTML5::DOM->TAG_MSTYLE
HTML5::DOM->TAG_MSUB
HTML5::DOM->TAG_MSUP
HTML5::DOM->TAG_MSUBSUP
HTML5::DOM->TAG__END_OF_FILE
HTML5::DOM->TAG_LAST_ENTRY
ENCODINGS
Supported encoding names
AUTO, NOT-DETERMINED, X-USER-DEFINED,
BIG5, EUC-JP, EUC-KR, GB18030, GBK, IBM866, MACINTOSH, X-MAC-CYRILLIC, SHIFT_JIS,
ISO-2022-JP, ISO-8859-10, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, ISO-8859-2,
ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-8-I,
WINDOWS-1250, WINDOWS-1251, WINDOWS-1252, WINDOWS-1253, WINDOWS-1254,
WINDOWS-1255, WINDOWS-1256, WINDOWS-1257, WINDOWS-1258, WINDOWS-874,
UTF-8, UTF-16BE, UTF-16LE, KOI8-R, KOI8-U
Supported encoding id consts
HTML5::DOM::Encoding->DEFAULT
HTML5::DOM::Encoding->AUTO
HTML5::DOM::Encoding->NOT_DETERMINED
HTML5::DOM::Encoding->UTF_8
HTML5::DOM::Encoding->UTF_16LE
HTML5::DOM::Encoding->UTF_16BE
HTML5::DOM::Encoding->X_USER_DEFINED
HTML5::DOM::Encoding->BIG5
HTML5::DOM::Encoding->EUC_JP
HTML5::DOM::Encoding->EUC_KR
HTML5::DOM::Encoding->GB18030
HTML5::DOM::Encoding->GBK
HTML5::DOM::Encoding->IBM866
HTML5::DOM::Encoding->ISO_2022_JP
HTML5::DOM::Encoding->ISO_8859_10
HTML5::DOM::Encoding->ISO_8859_13
HTML5::DOM::Encoding->ISO_8859_14
HTML5::DOM::Encoding->ISO_8859_15
HTML5::DOM::Encoding->ISO_8859_16
HTML5::DOM::Encoding->ISO_8859_2
HTML5::DOM::Encoding->ISO_8859_3
HTML5::DOM::Encoding->ISO_8859_4
HTML5::DOM::Encoding->ISO_8859_5
HTML5::DOM::Encoding->ISO_8859_6
HTML5::DOM::Encoding->ISO_8859_7
HTML5::DOM::Encoding->ISO_8859_8
HTML5::DOM::Encoding->ISO_8859_8_I
HTML5::DOM::Encoding->KOI8_R
HTML5::DOM::Encoding->KOI8_U
HTML5::DOM::Encoding->MACINTOSH
HTML5::DOM::Encoding->SHIFT_JIS
HTML5::DOM::Encoding->WINDOWS_1250
HTML5::DOM::Encoding->WINDOWS_1251
HTML5::DOM::Encoding->WINDOWS_1252
HTML5::DOM::Encoding->WINDOWS_1253
HTML5::DOM::Encoding->WINDOWS_1254
HTML5::DOM::Encoding->WINDOWS_1255
HTML5::DOM::Encoding->WINDOWS_1256
HTML5::DOM::Encoding->WINDOWS_1257
HTML5::DOM::Encoding->WINDOWS_1258
HTML5::DOM::Encoding->WINDOWS_874
HTML5::DOM::Encoding->X_MAC_CYRILLIC
HTML5::DOM::Encoding->LAST_ENTRY
PARSER OPTIONS
Options for:
* HTML5::DOM::new
* HTML5::DOM::parse
* HTML5::DOM::parseChunkEnd
* HTML5::DOM::Tree::parseFragment
threads
Threads count, if 0 - parsing in single mode without threads (default 2)
This option affects only for HTML5::DOM::new.
async
If async 0 (default), then some parsing functions (such as
HTML5::DOM::parse, HTML5::DOM::parseChunkEnd,
HTML5::DOM::Tree::parseFragment) waiting for parsing done.
If async 1, you must manualy call "$tree->wait" and "$node->wait" for
waiting parsing done.
Or use non-blocking "$tree->parsed" and "$node->parsed" to determine
parsing state.
This options works only if "threads" > 0
ignore_whitespace
Ignore whitespace tokens (default 0)
ignore_doctype
Do not parse DOCTYPE (default 0)
scripts
If 1 - contents parsed to single text node (default)
If 0 - contents parsed to child nodes
encoding
Encoding of input HTML, if "auto" - library can tree to automaticaly
determine encoding. (default "auto")
Allowed both encoding name or id.
default_encoding
Default encoding, this affects only if "encoding" set to "auto" and
encoding not determined. (default "UTF-8")
Allowed both encoding name or id.
See for available encodings: "ENCODINGS"
encoding_use_meta
Allow use " " tags to determine input HTML encoding. (default 1)
See detectByPrescanStream.
encoding_prescan_limit
Limit string length to determine encoding by " " tags. (default
1024, from spec)
See detectByPrescanStream.
encoding_use_bom
Allow use detecding BOM to determine input HTML encoding. (default 1)
See detectBomAndCut.
BUGS
SEE ALSO
* HTML::MyHTML - more
low-level myhtml bindings.
* Mojo::DOM - pure perl HTML5 DOM
library with CSS selectors.
AUTHOR
Kirill Zhumarin
LICENSE
* HTML5::DOM - MIT
* Modest - LGPL 2.1
* MyHTML - LGPL 2.1
* MyCSS - LGPL 2.1