Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: using xml::simple with unknown xml structure

by injunjoel (Priest)
on Jul 14, 2005 at 17:50 UTC ( #474990=note: print w/replies, xml ) Need Help??

in reply to using xml::simple with unknown xml structure

Greetings all,
A bit off topic but here is a little script I use to investigate how XML::Simple is parsing my *.xml files
This is meant to be run from the same directory that contains the xml files. Nothing novel but I find it useful.
#!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; #get all the .xml files from this base directory unless(opendir(CNF, '.')){ die "Unable to open directory for reading\n"; } my @config_files = sort grep { /\.xml$/ && -f "$_"} readdir(CNF); #clean up close CNF; DISPLAY: { print "Please select a file for parsing:\n"; for(my $i = 1; $i-1 < scalar(@config_files); $i++){ print "\t$i. $config_files[$i-1]\n"; } print "\n\t# "; } my ($filenum, $filename); chomp($filenum = <STDIN>); if($filenum !~ /^\d$/){ print "Please select the number\n"; goto DISPLAY; }else{ $filename = $config_files[$filenum-1]; } unless(open(CNF, $filename)){ die "unable to open XML config file". $!; }else{ my $file = do {local $/ = undef; <CNF>}; close CNF; my $xs = new XML::Simple(); my $ref = $xs->XMLin($file); print "\nXML structure (current).\n"; print Dumper($ref); print "\n"; ENDING:{ print "\n Q to quit\n"; my $key; chomp($key = <STDIN>); unless($key =~ /q/i){ goto ENDING; }else{ exit; } } }

"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://474990]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2019-07-15 18:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found