Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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?
[Corion]: A good morning to you too, marto!
[marto]: hey Corion, good weekend?
[prospect]: Thank you
[marto]: no problem prospect
[Corion]: I hope you all spent a good weekend!
[Discipulus]: good morning eumonks!

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2017-07-24 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (348 votes). Check out past polls.