Hi,
I am having a great deal of difficulty getting Perl to parse an XML file into useful perl data structures.
Specifically, I have written a perl script (several actually all a bit different), that is supposed to parse an xml file on the filesystem, then, at the least push generated key-value pairs onto a stack that I can work with.
I can get the script to parse the xml document and print, however if I try to do *anything* else with the data, it times out the script.
The xml file is available
http://www.foxengines.net/real-estate/properties.xml
Following is the script that works but doesnt do anything useful...
--------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
use XML::Parser;
my $file = '/big/dom/xfoxengines/www/real-estate/properties.xml';
print "Content-type: text/html\n\n";
my $parser = new XML::Parser(ErrorContext => 2);
$parser->setHandlers( Start => \&set_key,
Char => \&char_handler);
$parser->parsefile($file);
sub set_key {
my ($p, $key) = @_;
$curr_key = $key;
}
sub char_handler {
my ($p, $data) = @_;
print "<B>DEBUG:</B> char_handler being called with p, data: "$p", "$data"<BR />";
}
print "done.";
--------------------------------------------------------------------------------------------------
Now, to get it to really have problems, all I need to do is try to do something useful with the data, like put key-value pairs into a stack for dealing with later....
--------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
use XML::Parser;
my $file = '/big/dom/xfoxengines/www/real-estate/properties.xml';
print "Content-type: text/html\n\n";
my $parser = new XML::Parser(ErrorContext => 2);
$parser->setHandlers( Start => \&set_key,
Char => \&char_handler);
$parser->parsefile($file);
sub set_key {
my ($p, $key) = @_;
$curr_key = $key;
}
sub char_handler {
my ($p, $data) = @_;
push @stuff, "$curr_key=$data";
print "<B>DEBUG:</B> char_handler being called with p, data: "$p", "$data"<BR />";
}
print "done.";
--------------------------------------------------------------------------------------------------
The script never seems to reach the "print "done.";" line.
I have written scripts using XML::Parser, XML::Dumper, XML::Simple, and XML::DOM. I haven't gotten any of them to work enough to be useful.
Anyone have any hints?
Thanks,
Rich.