CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
XML::Parser inside a class

 



dabeat
New User

Sep 4, 2009, 1:17 AM

Post #1 of 4 (1073 views)
XML::Parser inside a class Can't Post

Hello,

I am using XML::Parser to make an XML parser. I would like to use it inside a class. I have my class in a module (MyClass.pm) I have created. The problem is it does not work when I try to use it inside my class. I think the problem is related to the way class methods are defined in Perl. As the first method line must be something like:

my $self = shift;


It seems XML::Parser has problems with it.

I have found that the PHP XML parser uses the method:


xml_set_object($this->parser, $this);


in order to notify the parser that handlers are implemented in this class.


Is there any way to use XML::Parser in OOP?

Thanks in advanced.


FishMonger
Veteran / Moderator

Sep 4, 2009, 5:27 AM

Post #2 of 4 (1067 views)
Re: [dabeat] XML::Parser inside a class [In reply to] Can't Post


Quote
Is there any way to use XML::Parser in OOP?


The answer is Yes. After all, XML::Parser is itself an OO module and it can be used in other OO modules.

Show use your code and a more compete explanation of the problem and include any/all errors and warnings that your code produces.


FishMonger
Veteran / Moderator

Sep 4, 2009, 5:29 AM

Post #3 of 4 (1065 views)
Re: [dabeat] XML::Parser inside a class [In reply to] Can't Post

Here's a related thread that might help.

http://perlguru.com/gforum.cgi?post=41119;sb=post_latest_reply;so=ASC;forum_view=forum_view_collapsed;;page=unread#unread


dabeat
New User

Sep 4, 2009, 8:12 AM

Post #4 of 4 (1060 views)
Re: [FishMonger] XML::Parser inside a class [In reply to] Can't Post

Please, find attached an abridged version of my class.

The class has a contructor and three methods:

index_corpus
build_command
parseData

In this version, the three handlers aren't defined as class methods, as it neither worked. Are defined as 'standard' methods, but inside the .pm file.

The error I get when I call 'build_command' method, which calls the parser, is:

read error at /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi/XML/Parser/Expat.pm line 469.

When I tried the handlers as a class methods, I added:

my $self = shift;

in the first line of the handlers, but I don't know if this causes a conflict with the parser, as the handler does not seem to expect that.


(This post was edited by dabeat on Sep 5, 2009, 1:09 AM)
Attachments: MyClass.pm (1.68 KB)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives