#!/usr/bin/perl --
use strict;
use warnings;
use XML::LibXML 1.70; ## for load_html/load_xml/location
my $xml = q{<contrib-group>
<contrib contrib-type="author">
.
some code
.
<x>, </x></contrib>
<contrib contrib-type="author">
.
some code
.
<x>, </x></contrib>
<contrib contrib-type="author">
.
some code
.
<x> and </x></contrib>
<contrib contrib-type="author">
.
some code
.
</contrib>
</contrib-group>
};
my $dom = XML::LibXML->new(qw/ recover 2 /)->load_xml(
#~ location => $filepath_or_http,
string => $xml,
);
print $dom->find(q{ //contrib/x[ contains( . , ' and ' ) ] })->
+shift->nodePath, "\n";
if( my $cx = $dom->findnodes(q{ //contrib/x })->pop ){
print $cx->nodePath, "\n";
print "$cx\n";
my $tx = $cx->textContent;
$tx =~ s/ and / , /;
$cx->removeChildNodes;
$cx->appendText( $tx );
print "$cx\n\n\n";
}
print "$dom\n";
__END__
/contrib-group/contrib[3]/x
/contrib-group/contrib[3]/x
<x> and </x>
<x> , </x>
|