#!/usr/bin/perl use strict; use warnings; use XML::LibXML; local $/; my $xml = <DATA>; print $xml, "\n"; my $parser = XML::LibXML->new(); my $doc = $parser->parse_string( $xml ); my $nodes = $doc->findnodes( '/msg/text()' ); my $node = $nodes->pop(); my $string = $node->data; $string =~ s/^As a last resort //; $string =~ s/is also/is extremely/; $node->setData( $string ); $node->appendData( " ... and XML::LibXSLT too!" ); print $doc->toString(); __DATA__ <?xml version="1.0" encoding="iso-8859-1"?> <msg>As a last resort XML::LibXML is also useful.</msg>
In reply to Re^2: Replacing things in XML files
by derby
in thread Replacing things in XML files
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |