开发者

HTML::Element -> Replace text node with new HTML::Element

How to replace a text node with new <p>test</p> i开发者_运维技巧n 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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜