karavay has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone thanks for sparing some time and looking at this thread – I need some help with inserting new element in to a tree not directly but through a variable possibly

code – works fine but does not fully meet my needs

... my $ele = $tree->look_down(_tag=> 'div',id=>'right'); $ele->delete_content(); my $i=0; while ($i < $right_panel) { #element friendly node $ele->push_content(['strong'], "$matrix_title[$i]",['p'],"$mat +rix_summary[$i]",['br'],['br'],['a', {href=>"art.cgi?art=$matrix_id[$ +i]"}, "Read on ... ", ],['br'],['hr'],['br']); $i++; } ... print $cgi->header(); print $tree->as_HTML();


basically I need to replace some symbols (user friendly tags) in $matrix_title[$i],$matrix_summary[$i] ( which are part of the news article fetched from the database and inserted in to a tree through push_content()) with valid tree element tags . e.g:

\n -> [br] <p> -> [p] [link = permonks.org] - > ['a', {href=>"perlonks.org"}]
etc...

– and have it all as a valid tree element.

Thanks,

Update

Found one partial Solution -

... while ($i < $right_panel) { $matrix_summary[$i]=~s/\n/<br>/g; #my $htm_elem = qq(['strong'], "$matrix_title[$i]",['p'],"$matrix_ +summary[$i]",['br'],['br'],['a', {href=>"art.cgi?art=$matrix_id[$i]"} +, "Read on ... ", ],['br'],['hr'],['br']); my $li=HTML::Element->new('~literal','text', qq(<strong> $matrix_t +itle[$i]</strong><p>$matrix_summary[$i]</p><br><a href="art.cgi?art=$ +matrix_id[$i]">Read on ...</a><br><hr><br>) ); $ele->push_content($li); $i++; }

Replies are listed 'Best First'.
Re: HTML::Element - tree element
by Anonymous Monk on Feb 14, 2008 at 12:36 UTC