XP is just a number | |
PerlMonks |
XML::Parser Object Orientation problemby shug94 (Sexton) |
on Aug 28, 2009 at 08:49 UTC ( [id://791855]=perlquestion: print w/replies, xml ) | Need Help?? |
shug94 has asked for the wisdom of the Perl Monks concerning the following question:
I find that XML::Parser works really well for parsing XML files. The problem is that if I try to use XML::Parser from within a Perl Class, then it cannot alter any of the fields of that class.
Generally the first argument passed to functions in Perl classes is an instance of the class (basically a 'this' pointer). However when using XML:Parser, I define a series of handler functions, which are passed to the parser object during construction, like so:
And these handler functions are NOT passed an instance of the current object, but are passed an instance of expat, the underlying XML parsing engine. As such, when I have finished parsing a tag, I cannot add its information to the variables of the current object, because I have no reference to the current object. My only option appears to be adding them to a variable with a package scope. (i.e. if my package is MyXMLProcessor, then I can store the results in %MyXMLProcessor::xmlTagContainer or somesuch) The problem arises in that my code could get called in rapid succession in parallel. Could the two copies of %MyXMLProcessor::xmlTagContainer overwrite each other and cause issues? My scripts are sitting on an Apache HTTP Server, and are started by HTTP Requests from an agent external to the server. My other idea is to have a package level hash, with a key that is the Expat instance, then each instance of Expat (which should be unique) gets its own copy of the container variable to fill. Is this idea legit? And my last alternative is to either use a different XML Parser, or to override the functionality of this one to accept an additional parameter, the current object. Any suggestions?
Back to
Seekers of Perl Wisdom
|
|