HTML::Object::DOM::Text - HTML Object DOM Text Class
use HTML::Object::DOM::Text; my $text = HTML::Object::DOM::Text->new( value => $some_text ) || die( HTML::Object::DOM::Text->error, "\n" );
v0.2.0
It inherits from HTML::Object::Text and HTML::Object::DOM::CharacterData
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------------+ +-------------------------+ | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::CharacterData | --> | HTML::Object::DOM::Text | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------------+ +-------------------------+ | ^ | | v | +-----------------------+ | | HTML::Object::Text | -----------------------------------------------------------------------------------------------------------------+ +-----------------------+
Normally this is a read-only property, but under perl, you can set or get a HTML::Object::DOM::Element::Slot object associated with the element.
See also Mozilla documentation
Sets or gets the text value for this element.
The read-only wholeText property of the HTML::Object::DOM::Text interface returns the full text of all Text nodes logically adjacent to the node. The text is concatenated in document order. This allows specifying any text node and obtaining all adjacent text as a single string.
wholeText
It returns a string with the concanated text.
Example:
<p id="favy">I like <span class="maybe-not">Shochu</span>, Dorayaki and Natto-gohan.</p> $doc->getElementsByTagName('span')->[0]->remove; # Now paragraph contains 2 text nodes: # 'I like ' # ', Dorayaki and Natto-gohan.' say $doc->getElementById('favy')->getFirstChild->wholeText; # I like , Dorayaki and Natto-gohan.
Returns an empty list in list context, or an empty array reference in scalar context.
Returns an empty list in list context, or undef in scalar context.
undef
Returns the parent node, if any.
Returns the root node
Returns the text value of this comment, i.e. the text between <!-- and -->
<!--
--
Provided with a node, this will return true if it is inside this text's parent or false otherwise.
Returns false.
Returns true.
Provided with another element object, and this returns true if both text element are the same, or false otherwise.
Set or get this text's parent node
This method of the Text interface replaces the text of the node and all of its logically adjacent text nodes with the specified text. The replaced nodes are removed, except the current node.
text
It returns the current node with the newly text set.
<p id="favy">I like apple,<span class="and"> and</span> orange,<span class="and"> and</span> kaki</p> $doc->getElementsByTagName('span')->foreach(sub { $_->remove; }); # Now text is: I like apple, orange, kaki # which are 3 text nodes # Take the 2nd one (for example) and set a new text for it and its adjacent siblings $doc->getElementById('favy')->getChildNodes->[1]->replaceWholeText( 'I like fruits' ); # Now the whole chunk has become: # <p id="favy">I like fruits</p>
Provided with an offset position and this method breaks the Text node into two nodes at the specified offset, keeping both nodes in the tree as siblings.
offset
After the split, the current node contains all the content up to the specified offset point, and a newly created node of the same type contains the remaining text. The newly created node is returned to the caller. If the original node had a parent, the new node is inserted as the next sibling of the original node. If the offset is equal to the length of the original node, the newly created node has no data.
It returns the newly created Text node that contains the text after the specified offset point.
It returns an HTML::Object::IndexSizeError if the specified offset is greater than the size of the node's text.
HTML::Object::IndexSizeError
<p>foobar</p> my $p = $doc->getElementsByTagName('p')->first; # Get contents of <p> as a text node my $foobar = $p->firstChild; # Split 'foobar' into two text nodes, 'foo' and 'bar', # and save 'bar' as a const my $bar = $foobar->splitText(3); # Create a <u> element containing ' new content ' my $u = $doc->createElement('u'); $u->appendChild( $doc->createTextNode( ' new content ' ) ); # Add <u> before 'bar' $p->insertBefore( $u, $bar ); # The result is: <p>foo<u> new content </u>bar</p>
Returns the content of the comment as a string.
Jacques Deguest <jack@deguest.jp>
Mozilla documentation
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.
To install HTML::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Object
CPAN shell
perl -MCPAN -e shell install HTML::Object
For more information on module installation, please visit the detailed CPAN module installation guide.