From: Andrew Gaffney <mailto:[EMAIL PROTECTED]> wrote:
: I've created a module that uses HTML::Parser to parse some
: HTML and create a tree structure. Someone had suggested to
: use HTML::TreeBuilder, but my HTML contains HTML::Mason
: code embedded, and HTML::TreeBuilder doesn't handle that
: well at all. HTML::TreeBuilder also adds <body>, <head>,
: and <html> tags when there aren't any in the document it
: is parsing. The files I'm using this with are only parts
: of HTML pages, so I don't want that stuff added.
: : My module works well enough, but I'm getting to the point
: where I need multiple parse trees existing at the same
: time in a mod_perl environment. The way my module is now,
: they could get mixed up, because I can't find a way to
: pass a custom variable to the event handler subroutines
: of HTML::Parser. : : I've figured that if I subclass it, I can create a new
: object for each parse tree instead of just returning an
: array reference. Here is my current code: : : package SkylineEdit;
: : use HTML::Parser ();
: : @ISA = ('Exporter');
: @EXPORT = ('html_to_htmltree', 'htmltree_to_html',
: 'get_node_content',
: 'set_node_content');
Comment out the exporter stuff and start a new module. For lack of imagination I used SkylineEditOO.pm. This should cache everything the way you want and requires little editing of SkylineEdit.pm.
<SNIP>
Since I hadn't gotten a response within a day of posting, I ended up modifying my code to store both parse trees that I needed in one $htmltree. This worked out well since both parse trees are from the same document. Thanks for the code, though. I can use it as an example when I run into this kind of problem again.
-- Andrew Gaffney Network Administrator Skyline Aeronautics, LLC. 636-357-1548
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>