Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to fetch a portion of a XML file to save it in another xml file

by runrig (Abbot)
on Sep 06, 2013 at 15:45 UTC ( [id://1052730]=note: print w/replies, xml ) Need Help??


in reply to How to fetch a portion of a XML file to save it in another xml file

Here's an example using XML::Rules. The only tricky part is the DOCTYPE handler, which I'm not totally sure about, but it works for your example:
use XML::Rules; use Data::Dumper; my $xml = <<XML; <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Automation Suite" verbose="1" parallel="false"> <test name="Configuration Restore Test Suite"> <classes> <class name="com.qa.testsuite.ConfigurationRestoreTests" /> </classes> </test> <test name="Import Test Suite"> <classes> <class name="com.qa.testsuite.ImportTests" /> </classes> </test> </suite> XML my @rules = ( '^test' => sub { $_[1]->{name} eq 'Import Test Suite' }, ); my $xr = XML::Rules->new( style => 'filter', rules => \@rules, handlers => { Doctype => sub { my (undef, $name, $sysid) = @_; print qq(<!DOCTYPE $name SYSTEM "$sysid">\n); }}, );
  • Comment on Re: How to fetch a portion of a XML file to save it in another xml file
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1052730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found