You would need to add file I/O error handling, and perhaps handle cases of missing tags. I assumed an input file named data. I assumed that the value inside <h1>...</h1> was used in the file name, because there is no reference to 'test' in the file, and perhaps you meant 'text' instead. But despite the caveats, this does something like you wanted:
#! /usr/bin/perl -w use strict; my $text; if (open INPUT, '<data') { local $/; $text = <INPUT>; close INPUT; } while ($text =~ /<\?split \?>(.*?)(?=<\?split \?>)/sg) { my $fragment = $1; my ($h1) = $fragment =~ /<h1>(.*?)<\/h1>/is; my ($from, $to) = $fragment =~ /<no>(.*?)<\/no>/isg; if (open OUTPUT, ">${h1}-nr${from}to${to}.xml") { print OUTPUT $fragment; close OUTPUT; } } exit 0;
In reply to Re: Splitting XML file on Processing Instructions
by pbeckingham
in thread Splitting XML file on Processing Instructions
by Wappel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |