NAME

HTML::Object::DOM::Text - HTML Object DOM Text Class

SYNOPSIS

use HTML::Object::DOM::Text;
my $text = HTML::Object::DOM::Text->new( value => $some_text ) || 
    die( HTML::Object::DOM::Text->error, "\n" );

VERSION

v0.2.1

DESCRIPTION

It inherits from HTML::Object::Text and HTML::Object::DOM::CharacterData

INHERITANCE

+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------------+     +-------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::CharacterData | --> | HTML::Object::DOM::Text |
+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------------+     +-------------------------+
  |                                                                                                                                        ^
  |                                                                                                                                        |
  v                                                                                                                                        |
+-----------------------+                                                                                                                  |
|  HTML::Object::Text   | -----------------------------------------------------------------------------------------------------------------+
+-----------------------+

PROPERTIES

assignedSlot

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

nodeValue

Sets or gets the text value for this element.

wholeText

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.

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.

See also Mozilla documentation

METHODS

getAttributes

Returns an empty list in list context, or an empty array reference in scalar context.

getChildNodes

Returns an empty list in list context, or an empty array reference in scalar context.

getElementById

Returns an empty list in list context, or undef in scalar context.

getFirstChild

Returns an empty list in list context, or undef in scalar context.

getLastChild

Returns an empty list in list context, or undef in scalar context.

getParentNode

Returns the parent node, if any.

getRootNode

Returns the root node

getValue

Returns the text value of this comment, i.e. the text between <!-- and -->

is_inside

Provided with a node, this will return true if it is inside this text's parent or false otherwise.

isAttributeNode

Returns false.

isCommentNode

Returns true.

isElementNode

Returns false.

isEqualNode

Provided with another element object, and this returns true if both text element are the same, or false otherwise.

isNamespaceNode

Returns false.

isPINode

Returns false.

isProcessingInstructionNode

Returns false.

isTextNode

Returns true.

parent

Set or get this text's parent node

replaceWholeText

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.

It returns the current node with the newly text set.

Example:

<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>

See also Mozilla documentation

splitText

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.

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.

Example:

<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>

See also Mozilla documentation

string_value

Returns the content of the comment as a string.

toString

Returns the content of the comment as a string.

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Mozilla documentation

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.