Ironically I am using XML::LibXML later on in the same program. I opted to use XML::Simple because XML::LibXML was choking on a very large file. My solution was to break it up into smaller sections so that the majority of the data could be parsed. XML::Simple has no problem reading in all the data I fed it, but the outputing structure is not what I desired.
My ultimate conclusion was to skip a data structure altogether for breaking up the file and just do a straight regex across the whole file. This preserves my structure exactly and allows me to specify which tags to separate across. Since I am working with a set standard (docbook) there should be no surprising or malformed tags (unless I am fed a corrupted file).
What you said about being beyond XML::Simple's capabilities, led me in this direction. Thanks for letting me know that it was time to go down another path.
sub splitNode2{
my ($name, $root, $tag, $filename) = @_;
#print "opening file [$filename]\n";
if(!open(READ, "$filename")){
die "Cannot open file [$filename] for reading\n";
}
my $content = "";
while(my $line = <READ>){
$content .= $line;
}
#print "matching <$tag>\n";
my @matches = $content =~ /(<$tag.*?>.*?<\/$tag>)/sg;
if(scalar(@matches) < 1){
writeFile($name, "", $content); #writes the string to a file
return 0;
}
my $count = 1;
foreach (@matches){
writeFile("$name"."_"."$count", "", $_);
$count++;
#print "match: $_\n\n\n";
}
}
|