Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

10. Modifying HTML with Trees > 10.5. Creating New Elements

Creating New Elements

So far we haven’t directly created any new HTML::Element objects. All the elements that have appeared thus far were created by HTML::TreeBuilder as part of its delegated task of building whole trees. But suppose that we actually do need to add something to a tree that never existed elsewhere in that or any other tree. In the above section, we actually snuck in creating a new node in this statement:

$template_title->push_content( 'No title' );

But that’s hardly an amazing feat, because that node isn’t a real object. You can actually create a new object by calling HTML::Element->new(' tagname '). So this would add an hr element to a given paragraph object:

my $hr = HTML::Element->new('hr');
$paragraph->push_content($hr);

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint