Hello Monks,
How do I parse multiple xml files with xml::twig?
I am sure I'm missing something really obvious here
but i have read and reread the twig documentation, googled and perlmonked and I cant discover why when I run this only file2.xml gets parsed.
How can I 'reset' the twig to parse the next file? has anyone else experience this sort of problem and if so how did you solve it? thanks,;+)
@xmlfiles = qw(file1.xml file2.xml);
foreach my $xfile (@xmlfiles)
{
$twig = new XML::Twig(
twig_roots => {
'pdb_entry/pdb_code' => \&pdb_entry,
'pdb_entry/total_asm' => \&pdb_entry,
'pdb_entry/asm_set/assembly' => \&assembly,});
&parse_twig($xfile);
}
sub parse_twig
{
my $file = shift;
if ($twig->safe_parsefile($file) == 0)
{
die "Failed to parse $file: $@";
}
my $root = $twig->root;
my @params = $root->children('pdb_entry');
$twig->purge;
$twig->dispose;
}
...
handler code here
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.