ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
XML::SAX::Expat - can't stop parsing
by Aaron Straup Cope other posts by this author
Sep 4 2002 3:50PM messages near this date
view in the new Beta List Site
Re: XML::SAX::Expat - can't stop parsing | Re: XML::SAX::Expat - can't stop parsing
Hi all,

I'm not sure if this is a bug or just a config option that I missed but I
am encountering decidely bad bevahiour when try to use XML::SAX::Expat in
a mod_perl context.

I have a directory full of DocBook and plain-text documents for browsing
on the web. The directory index is generated using a handler that calls
XML::Filter::XML_Directory_2XHTML [1].

The handler tries to determine and present <articleinfo>  data for each
file using the 'set_handlers' method (code included below)

In turn the file is parsed using XML::SAX::ParserFactory and relevant data
passed off to a XML::SAX::Writer handler.

The problem is that XML::SAX::Expat tries to parse the first file and ends
up making a sub request (?) to the actual HTTP uri which precipitates a
loop.

I'm not entirely sure that's what happening but I traced stuff as far as
the call to 'ParseStream' in XML::Parser::Expat which I gather is using
DynaLoader magic that I know nothing about :-(

If I use the default parser provided by ::ParserFactory and everything
works fine.

I am just stupid or is there a bug somewhere in all of this?

Thanks,

[1] http://search.cpan.org/author/ASCOPE/XML-Filter-XML_Directory_2XHTML/

***********

Parsing /usr/local/procedures/3.0...
# XML::SAX::Expat::_handler_start
started document
Parsing /usr/local/procedures/3.0...
Parsing /usr/local/procedures/3.0...
Parsing /usr/local/procedures/3.0...
Parsing /usr/local/procedures/3.0...
Parsing /usr/local/procedures/3.0...
Parsing /usr/local/procedures/3.0...

************

...

$filter-> set_handlers({file=>ArticleInfo->new(Handler=>$writer)})

...

package ArticleInfo;
use base qw (XML::SAX::Base);

use XML::SAX::ParserFactory;
$XML::SAX::ParserPackage = "XML::SAX::Expat";

use File::Basename;

sub parse_uri {
  my $self = shift;
  my $uri  = shift;

  my $filter = LocalSAX_ActuallyGetArticleInfo-> new(Handler=>$self->{Handler});
  my $parser = XML::SAX::ParserFactory-> parser(Handler=>$filter);

  # Since it is reasonable to expect that we might be
  # reading from a non-DocBook document, we try to make
  # sure to fail gracefully when the XML parser croaks.

  print STDERR "Parsing $uri...\n";
  eval { $parser-> parse_uri($uri); };
  print STDERR "ok\n";

  if ($@) {
    $self-> SUPER::characters({Data=>&basename($uri)});
  }
}







_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Aaron Straup Cope
Robin Berjon
Aaron Straup Cope
Robin Berjon

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved