On Thu, Jul 08, 2004 at 11:16:00PM -0500, Eric Lease Morgan wrote: > Has anybody here written one or more Perl scripts using XML::LibXML to > find & replace in XML documents?
Sounds like you could probably use the XPath features in XML::LibXML to isolate the nodes you want to change, update them, and then output them again. As an example I pulled a TEI file down from here: http://www.unc.edu/awmc/tei/teiAWMCWORK1375.xml And I wrote this program to change the title element: #!/usr/bin/perl use strict; use warnings; use XML::LibXML; ## create the parser, and the dom object my $parser = XML::LibXML->new(); my $doc = $parser->parse_file( 'foo.xml' ); ## extract the first title text node my $nodes = $doc->findnodes( '/TEI.2/teiHeader/fileDesc/titleStmt/title/text()' ); my $node = $nodes->pop(); ## update the content $node->setData( "The adventures of Huckleberry Finn" ); ## output print $doc->toString(); The XML::LibXML docs sure are daunting, I'll agree there. //Ed -- Ed Summers aim: inkdroid web: http://www.inkdroid.org Well it's too bad the machine that we built would never save us, that's what they say... [Jimi Hendrix]