Unfortunately the suggestions offered to an earlier query did not work. I am trying to use Twig to split a file that has <MyConnectData> as the root and <Message>
as the first child. My code below does work when there is only one <Message> element. When there is more than one <Message> element the error that is generated is:
Can't call method "text" on and undefined value at line 11.
I'm new enough at this that I need the simplest possbile explanation as to how I can use this code to read more than
one <Message> element in the .xml file.
Thanks in advance.
---------------------------------------------
use XML::Twig;
my $field= $ARGV[0] || 'ppg';
my $twig= new XML::Twig;
$twig->parsefile( "mydata.xml");
my $root= $twig->root;
my @Messages= $root->children;
my @sorted= sort { $b->first_child( $field)->text
<=> $a->first_child( $field)->text }
@Messages;
print '<?xml version="1.0"?>';
print '<!DOCTYPE stats SYSTEM "stats.dtd" []>';
print '<MyConnectData>';
foreach my $Message (@sorted)
{ $Message->print;
open (fh, '>>F:/perl/datafiles/test.xml');
$twig->print(\*fh);
close fh;
}
print "</MyConnectData>\n";
In reply to Splitting XML file ... by xmlsql
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |