FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > General Coding/Development
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 12-22-2002, 09:03 AM   Postid: 78875
rfox001
Visitor

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Dec 2001
Posts: 7
Perl-XML Parser Troubles

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: &quot;$p&quot;, &quot;$data&quot;<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: &quot;$p&quot;, &quot;$data&quot;<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.
rfox001 is offline   Reply With Quote
Old 12-22-2002, 09:12 AM   Postid: 78876
rfox001
Visitor

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Dec 2001
Posts: 7
My real goal here...

Hi,

FWIW, my real goal here is to get an array of objects that I can use to look at the data under various conditions, very much like how the XML parsing in PHP works, i.e. returning a list of objects.

Thanks,
Rich.
rfox001 is offline   Reply With Quote
Old 12-22-2002, 09:56 AM   Postid: 78878
Rich
Merchant Rep
 
Rich's Avatar

Forum Notability:
153 pts: Ambassador of Goodwill
[Post Feedback]
 
Join Date: Nov 1998
Location: Indiana, USA
Posts: 1,658
And the errors listed in your error log are?....
__________________
Rich
E-Commerce Solutions:
www.rsmarketing.com
Domain Name Registrations:
www.domain-registration-zone.com
Time Zone Converter:
www.timezoneconverter.com
Rich is offline   Reply With Quote
Old 12-22-2002, 10:06 AM   Postid: 78879
rfox001
Visitor

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Dec 2001
Posts: 7
No errors in log, script works now... What?!

Hi,

Well, I just cleared the log and re-ran the script with the offending line included to see what error shows up (I don't think that on previous runs it showed an error), and it worked just happily.

uurgh.

I must've pulled some inviso-gremlin out when I was cleaning the script up for posting on this board. Double-urgh.

If I can reproduce the error now, I will repost. This was a very reliable problem this morning.

Thanks,
Rich.
rfox001 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 05:27 AM.


Running on vBulletin®
Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2013 FutureQuest, Inc.
FutureQuest, Inc.