I'm trying (reasonably successfully, to a point) XML files using XML-Twig, however I'm encountering some undesirable output issues.
Input file is received, of the format
<EXPORT>
<OUTPUT>2008-01-01</OUTPUT>
<RECORD>.....</RECORD>
<RECORD>.....</RECORD>
....
</EXPORT>
I'm looking to retrieve certain RECORD elements from the file - which I can isolate using handlers without any problem (the code below is just a sample).
sub record_check {
my( $nhf, $record)= @_;
my $member = $record->first_child('ID')->text;
if ( $member <1000 ) {
$nhf->flush();
print "\n";
}
$nhf->purge();
}
my $nhf= XML::Twig->new( twig_roots => { RECORD => 1, },twig_handlers
+=> { RECORD => \&record_check,}, );
$nhf->parsefile( $input_file );
$nhf->purge;
I was expecting to see
<RECORD>...........</RECORD>
<RECORD>...........</RECORD>
....
but instead, if the first RECORD matches my query, I get
<EXPORT><RECORD>............</RECORD>
<RECORD>...........</RECORD>
....
everything is OK if the first RECORD doesn't match.
Anyone got any ideas how I can get rid of the unwanted <EXPORT> at the beginning of the output; I had hoped using TWIG_ROOT would solve the problem, but apparently not.
BTW - The input file is HUGE, so use of triggers is a MUST as otherwise building the entire tree takes an enormous amount of time and memory.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.