#!/usr/bin/perl --
use strict;
use warnings;
use XML::LibXML 1.70; ## for load_html/load_xml/location
my $xml = q{
.
some code
.
,
.
some code
.
,
.
some code
.
and
.
some code
.
};
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
and
,