So I have a programming assignment where I need to parse multiple XML files and return their attributes in a readable format. Currently the script parses all of the files and stores all the details for each file at each position of an array. An example of the desired output would be:
J MIG-49 at location "85,20,0.1" is moving to "0.5,-0.5,-300
my $count=0;
opendir (DIR, "../folder") or die "$!";
my @feeds = grep {/threats.*?\.xml/} readdir DIR;
close DIR;
# The above 3 lines read in the XML files and store them in array feeds.
for $threats(@feeds) {
open (READ, $threats)||die"$!";
flock(READ, 1) || die "Can't lock xml: $!";
while (<READ>) {
$all[$count].=$_
}
close READ;
$count++;
}
print @all; # report
It actually does parse through. Those other examples are only for parsing a single XML file or a multi-level XML file. That's easy. This is multiple XML files within a loop.
Last edited by AngelBladeVII; April 9th, 2012 at 03:15 PM.
So then what's your problem if you already read through the files and already say that parsing XML is easy?
My problem is that I haven't been able to find any example that are allowing me to pull out specific attributes from each file. Honestly I'm relatively new to the syntax of Perl so I'm not quite sure how I would do this. I need to pull out the values for location, ftype, fmodel, and movement_speed for each file as that is the relevant information needed in this program. Sorry if I've been too vague and I appreciate your help.
Which is the exact problem I covered with my first reply to you. And you said that you could already do it because it was easy.
I know the example there does that, but that's for only one file, as opposed to multiple files within a directory. I'm not quite sure how to set up a loop to do it for multiple files.
Bookmarks