in reply to Re: Replacing things in XML files
in thread Replacing things in XML files
#!/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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Replacing things in XML files
by borisz (Canon) on Apr 26, 2006 at 20:38 UTC |