Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 ( #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
Node Status?
node history
Node Type: note [id://1052730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2014-07-31 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls