in reply to Need Help Understanding Parsing XML into multi level struck
My 1 line answer to anything XML is use XML::Simple
Heres why: you probably have some xml files lying around, these provide good fodder for parsing into data structures, you can DataDump these and see what happens! By simply redirecting the output to a file, you can then go backwards.
Theres a very good chance that XML::Simple will be the only tool you need. If not, it will get you a long way b4 you run out of gas.
to get you started
#!/usr/local/bin/perl -w
use XML::Simple;
use Data::Dumper;
$Data::Dumper::Indent=1;
use Getopt::Std;
getopts('w') or die "bad args";
foreach $file (@ARGV) {
if ($file =~ /.xml$/) {
$data = XMLin($file, suppressempty=>1);
if ($opt_w) {
$file =~ s|.*/(.*)\.xml|$1|;
open (STDOUT, "> $file.pm");
}
print "# xml as data\n", Dumper $data;
}
else {
$data = do $file;
# print "data: ", Dumper $data;
if ($opt_w) {
$file =~ s|.*/(.*)\.xml|$1|;
open (STDOUT, "> $file.xml");
}
print "\n", XMLout($data);
}
}
|
|---|