XML::LibXML:如何用节点内容替换节点?

问题描述 投票:0回答:1
html xml-libxml
1个回答
0
投票

好吧,我明白了。

use XML::LibXML;
use strict;
use warnings q(all);
my $dom = XML::LibXML->load_html( location => pop );
for ( $dom->findnodes("//a") ) {
    my $content = $_->textContent;
    my $t       = $dom->createTextNode($content);
    $_->replaceNode($t);
}
for ( $dom->findnodes("//img") ) {
    my $alt = $_->getAttribute("alt");
    my $t   = $dom->createTextNode($alt);
    $_->replaceNode($t);
}
print $dom->toString();
© www.soinside.com 2019 - 2024. All rights reserved.