--- Rob Dixon <[EMAIL PROTECTED]> wrote:
> Martin Thurn wrote:
> >   I ran into similar problems for my module WWW::Search.
> >   No, out-of-the-box you can not re-use an HTML::TreeBuilder object to parse
> >   a new file.
> 
> I'm pretty sure you're wrong about that. HTML::TreeBuilder subclasses
> HTML::Parser, which provides the 'new', 'parse', 'parse_file', and 'eof'
> methods. The documentation says:
> 
>         After $p->eof has been called, the parse() and parse_file() methods
>         can be invoked to feed new documents with the parser object.
> 
> which is poor English, but I understand it to mean that, once the 'eof'
> method has been called, any further calls to 'parse' or 'parse_file'
> will create a new HTML tree from scratch.

but from HTML::TreeBuilder,
 
"
$root->eof() 
This signals that you're finished parsing content into this tree; this runs various 
kinds of
crucial cleanup on the tree. This is called for you when you call 
$root->parse_file(...), but not
when you call $root->parse(...). So if you call $root->parse(...), then you must call 
$root->eof()
once you've finished feeding all the chunks to parse(...), and before you actually 
start doing
anything else with the tree in $root."

it said 'This is called for you when you call $root->parse_file'.

> >   The reason you can't re-use your HTML::Element is because it's a
> > reference, and when the tree gets deleted, your Element gets deleted right
> > along with it.
> 
> Once you have called $tree->delete the object no longer exists, but I
> believe $tree->delete_content or $tree->eof will allow you to reuse
> the same object for parsing a new document.
> 
> Rob
> 

i tried both delete_content and eof, it either yield error or the first file being 
parsed is
written to the rest of parsing file. something like this

define new tree $tree
in new sub, parse file with $tree, do something , then called $tree->delete_content 
or/and
$tree->eof


Qiang

 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Reply via email to