--- Rob Dixon <[EMAIL PROTECTED]> wrote: > James.Q.L wrote: > > > > I am trying to add html tag to an existing html file using HTML::TreeBuiler. > > > > the problem is that the added tags isn't encoded after the output. everything els > > is fine. > > > > ########### > > my $tree = HTML::TreeBuilder->new; > > $tree->no_space_compacting(1); > > $tree->store_comments(1); > > $tree->parse_file("f.html"); > > > > my $ele; > > my $tag = '<tr><td>TEST</td></tr>'; > > > > for (@{ $tree->extract_links('a', 'href') }) { > > my($link, $element, $attr, $tag) = @$_; > > if ($link=~ m{/mylink\.htm}) { > > $ele = $element; > > last; > > } > > } > > $ele = $ele->parent(); # td > > $ele = $ele->parent(); # tr > > my $r = $ele->postinsert($tag); > > > > open F,">f.html"; > > print F $tree->as_HTML('<>&',' ',{}); > > close F; > > $tree->delete; > > > > the output in html turn out to be > > > > <tr><td><b>TEST</b></td></tr> > > > > > > The 'postinsert' method expects an HTML::Element object to add > into the tree, not simple HTML text. The easiest way to build > what you want here is probably with the 'new_from_lol' method > like this. > > my $tag = HTML::Element->new_from_lol (['tr', ['td', 'TEST']]) > > HTH, > > Rob >
>From HTML::Element doc, $h->postinsert($element_or_text...) i suppose it means postinsert accept $element or text. and the insertion didn't yield any error with text as parameter.and it looks much simpler/easier than the new_from_lol. using HTML::Element->new_from_lol (['tr', ['td', 'TEST']]) did lead to the correct html output. but when i am not using 'TEST' directly in new_from_lol $insert= <<TEST; <tr><td>some more tags here</td></tr> TEST $h = HTML::Element->new_from_lol (['tr', ['td', $insert]]); then do postinsert($h); the tags in $insert still don't get decoded after output. any idea? Qiang __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com