HTML::O...terData(3)
πΈ NAME πΈ
HTML::Object::DOM::CharacterData β HTML Object Character Data Class. This is the HTML::O...terData(3) page, bestie, so buckle up π
π οΈ SYNOPSIS π οΈ
use parent qw( HTML::Object::DOM::CharacterData );
# then implements additional properties and methods
π·οΈ VERSION π·οΈ
v0.2.0
π DESCRIPTION π
The CharacterData abstract interface is the whole vibe for a Node object that contains characters β¨ It is an abstract interface, which means there are literally not any objects of type CharacterData: it gets implemented by other interfaces like Text, Comment, and Space, and those ones are not abstract. No cap.
It inherits from Node.
𧬠INHERITANCE π§¬
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::CharacterData |
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------------+
π PROPERTIES π
This interface also inherits properties from its parents Node and EventTarget. Iconic inheritance behavior, honestly π
π¦ data π¦
It is a string representing the textual data contained in this object. Simple, but make it fashion π«
Example:
<!-- This is an html comment !-->
<output id="Result"></output>
my $comment = $doc->body->childNodes->[1];
my $output = $doc->getElementById('Result');
$output->value = $comment->data;
# output content would now be: This is an html comment !
Setting the content of a text node using data
<span>Result: </span>Not set.
my $span = $doc->getElementsByTagName('span')->[0];
my $textnode = $span->nextSibling;
$textnode->data = "This text has been set using textnode.data."
See for more information: https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/data
π length π
Read-only, bestie π«Ά
Returns a number representing the size of the string contained in the object.
Example:
Length of the string in the <code>Text</code> node: <output></output>
use HTML::Object::DOM::Text;
my $output = $doc->getElementsByTagName('output')->[0];
my $textnode = HTML::Object::DOM::Text->new("This text has been set using textnode.data.");
$output->value = $textnode->length;
# Length of the string in the Text node: 43
See for more information: https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/length
π¦ nextElementSibling π¦
Read-only π
Returns the first Element that follows this node, and is a sibling, or undef if this node was the last one in its parent's children list. It's giving "who's next?" energy.
Example:
TEXT
<div id="div-01">Here is div-01</div>
TEXT2
<div id="div-02">Here is div-02</div>
<pre>Here is the result area</pre>
# Initially, set node to the Text node with `TEXT`
my $node = $doc->getElementById('div-01')->previousSibling;
my $result = "Next element siblings of TEXT:\n";
while( $node )
{
$result .= $node->nodeName + "\n";
# The first node is a CharacterData, the others Element objects
$node = $node->nextElementSibling;
}
$doc->getElementsByTagName('pre')->[0]->textContent = $result;
would produce:
TEXT
Here is div-01
TEXT2
Here is div-02
Next element siblings of TEXT:
#text
DIV
DIV
PRE
SCRIPT
See for more information: https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/nextElementSibling
πΈ previousElementSibling πΈ
Read-only π
Returns the first Element that precedes this node, and is a sibling, or undef if this node was the first one in its parent's children list. Lowkey the "look back" bestie of the sibling world.
Example:
<div id="div-01">Here is div-01</div>
TEXT
<div id="div-02">Here is div-02</div>
SOME TEXT
<div id="div-03">Here is div-03</div>
<pre>Result</pre>
# Initially set node to the Text node with `SOME TEXT`
my $node = $doc->getElementById('div-02')->nextSibling;
my $result = "Previous element siblings of SOME TEXT:\n";
while( $node )
{
$result .= $node->nodeName + "\n";
$node = $node->previousElementSibling;
}
$doc->getElementsByTagName('pre')->[0]->textContent = $result;
would produce:
Here is div-01
TEXT
Here is div-02
SOME TEXT
Here is div-03
Previous element siblings of SOME TEXT:
#text
DIV
DIV
See for more information: https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/previousElementSibling
π METHODS π
okay so this interface also inherits methods from its parents, Node and EventTarget β the whole family tree is showing up, and honestly? iconic π«Ά
π after π
Inserts a set of Node objects or strings into the children list of the CharacterData's parent, right after the CharacterData object. Just after it. No cap.
Strings get inserted as Text nodes β the string is literally handed over as an argument to the HTML::Object::DOM::Text constructor, bestie β¨
It returns an HTML::Object::HierarchyRequestError error when the new nodes cannot be inserted at the specified point in the hierarchy, that is if one of these conditions is met:
- If the insertion of one of the added node would lead to a cycle, that is if one of them is an ancestor of this
CharacterDatanode. - If one of the added node is not a
HTML::Object::DOM::DocumentFragment, anHTML::Object::DOM::Element, or aHTML::Object::DOM::CharacterData. - If this
CharacterDatanode is actually aTextnode, and its parent is aDocument. - If the parent of this
CharacterDatanode is aDocumentand one of the nodes to insert is aDocumentFragmentwith more than oneElementchild, or that has aTextchild.
Example:
my $h1TextNode = $doc->getElementsByTagName('h1')->[0]->firstChild;
$h1TextNode->after(" #h1");
$h1TextNode->parentElement->childNodes;
# NodeList [#text "CharacterData.after()", #text " #h1"]
say $h1TextNode->data;
# "CharacterData.after()"
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/after>
πΈ appendData πΈ
Provided with some string, and this appends the given string to the data string; when this method returns, data contains the concatenated string. It's giving "add it to the end and slay" π
Example:
<span>Result: </span>A text
my $span = $doc->getElementsByTagName("span")->[0];
my $textnode = $span->nextSibling;
$textnode->appendData(" - appended text.");
# span now contains:
# Result: A text - appended text.
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/appendData>
π¦ before π¦
Inserts a set of Node objects or strings in the children list of the CharacterData's parent, just before the CharacterData object. Same energy as after, just... before. Main character positioning honestly β¨
It returns the same error as after
Example:
my $h1TextNode = $doc->getElementsByTagName('h1')->[0]->firstChild;
$h1TextNode->before("h1# ");
$h1TextNode->parentElement->childNodes;
# NodeList [#text "h1# ", #text "CharacterData.before()"]
say $h1TextNode.data;
# "CharacterData.before()"
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/before>
π deleteData π
Provided with an offset value as an integer and an amount as a length, and this removes the specified amount of characters, starting at the specified offset, from the data string; when this method returns, data contains the shortened string. bye-bye characters, you had a good run π
Example:
<span>Result: </span>A long string.
my $span = $doc->getElementsByTagName("span")->[0];
my $textnode = $span->nextSibling;
$textnode->deleteData(1, 5);
# span now contains:
# Result: A string.
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/deleteData>
π§ insertData π§
Provided with an offset value as an integer and a string, and this inserts the specified characters, at the specified offset, in the data string; when this method returns, data contains the modified string. Sneaking text into the middle like it's a group chat message at 2am π
<span>Result: </span>A string.
my $span = $doc->getElementsByTagName("span")->[0];
my $textnode = $span->nextSibling;
$textnode->insertData(2, "long ");
# span now contains:
# Result: A long string.
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/insertData>
π remove π
Removes the object from its parent children list. Just straight-up yeeting it out of the chat, no explanation needed π
<span>Result: </span>A long string.
my $span = $doc->getElementsByTagName("span")->[0];
my $textnode = $span->nextSibling;
# Removes the text
$textnode->remove();
# span now contains:
# Result:
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/remove>
π₯ replaceData π₯
$e->replaceData($offset, $count, $data);
Provided with an offset value as an integer, an amount as a length, and a string, and this replaces the specified amount of characters, starting at the specified offset, with the specified string; when this method returns, data contains the modified string. Out with the old text, in with the new β makeover era π
<span>Result: </span>A long string.
my $span = $doc->getElementsByTagName("span")->[0];
my $textnode = $span->nextSibling;
$textnode->replaceData(2, 4, "replaced");
# span now contains:
# Result: A replaced string.
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/replaceData>
β replaceWith β
$e->replaceWith( $node1, 'some text', $node2 );
Provided with a list of node objects or strings, and this replaces the characters in the children list of its parent with the supplied set of node objects or strings. It's giving "swap the whole vibe" energy β¨
This returns an HTML::Object::HierarchyRequestError when the node cannot be inserted at the specified point in the hierarchy.
Example:
<p id="myText">Some text</p>
my $text = $doc->getElementById('myText')->firstChild;
my $em = $doc->createElement("em");
$em->textContent = "Italic text";
# Replace `Some text` by `Italic text`
$text->replaceWith( $em );
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/replaceWith>
π substringData π
Provided with an offset value as an integer, an amount as a length, and this returns a string containing the part of data of the specified length and starting at the specified offset. Basically it's doing a little peek-a-boo slice of your text π
This is effectively similar to perl's substr in perlfunc
Returns a new scalar object
It returns a HTML::Object::IndexSizeError error if offset + amount is larger than the length of the contained data. So like, don't ask for more characters than exist β the math has to math π
See for more information <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData/substringData>
πΈ AUTHOR πΈ
Jacques Deguest β jack@deguest.jp
π¦ SEE ALSO π¦
Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/CharacterData>
π COPYRIGHT & LICENSE π
Copyright(c) 2021 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π«Ά brought to you by perl v5.42.2, dated 2026-02-15, under the manpage name HTML::O...terData(3) β go forth and manipulate those character nodes responsibly πβ¨
π¦ where this page comes from
- alpine 3.24: perl-html-object-doc 0.6.0-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms