awk - Split an xml file into 2 halves in perl -


i have xml file in below format:

<installer> <plugins> . . . </plugins> </installer> <installer> <plugins> . . . </plugins> </installer>  

so, can see there 2 parts here i.e. 2 installer blocks. want segregate , redirect first installers part test1.xml file , second installers part test2.xml.

i know achieve same using loop. but, please provide me solution using sed/awk faster processing.

please please don't use regular expression or line based approach splitting xml. way lies brittle code , broken xml, , that's bad news concerned.

using xml posted in previous question reference point:

read xml file in perl

#!/usr/bin/perl  use strict; use warnings;  use xml::twig; use data::dumper;  $file_extn = 1;  sub split_installer {    ( $twig, $installer ) = @_;    open ( $output, ">", "test".$file_extn++.".xml" ) or warn !;    print {$ouput} $installer -> sprint();    close ( $output );  }  $twig = xml::twig -> new ( twig_handlers => { 'installer' => \&split_installer } ) -> parsefile ( 'your_file.xml ); 

a lot of accomplished utility xml_split.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -