How to replace a text node with new <p>test</p>
in HTML::Element?
Thanks in advance.
How to replace a text node with new <p>test</p>
in HTML::Element?
Thanks in advance.
This is Mak Killbers' own answer, ripped from his question to where it belongs:
=== Answering my own Question ===
$ele->objectify_text();
my @childNodes = $ele->content_list();
for(my $j=0; $j < scalar(@childNodes); $j++) {
my $childNode = $childNodes[$j];
if (ref($childNode) && ($childNode->tag() eq '~text')) { #TEXTNODE
my $newElement = HTML::Element->new('p');
$newElement->push_content($childNode->attr('text'));
$childNode->replace_with($newElement)->delete();
}
}
$ele->deobjectify_text();