The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HTML::Native::Document - HTML::Native document-level element

SYNOPSIS

    use HTML::Native::Document;

    my $doc = HTML::Native::Document::XHTML10::Strict->new ( "Home" );
    my $body = $doc->body;
    push @$body, (
      [ h1 => "Welcome" ],
      "Hello world!"
    );
    print $doc;
    # prints:
    #   <?xml version="1.0" encoding="UTF-8"?>
    #   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    #             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    #   < html xmlns="http://www.w3.org/1999/xhtml">
    #   <head><title>Home</title></head>
    #   <body><h1>Welcome</h1>Hello world!</body>
    #   </html>

DESCRIPTION

HTML::Native::Document provides several predefined HTML document types:

HTML::Native::Document::XHTML10::Strict - XHTML 1.0 Strict
HTML::Native::Document::XHTML10::Transitional - XHTML 1.0 Transitional
HTML::Native::Document::XHTML10::Frameset - XHTML 1.0 Frameset
HTML::Native::Document::XHTML11 - XHTML 1.1
HTML::Native::Document::HTML401::Strict - HTML 4.01 Strict
HTML::Native::Document::HTML401::Transitional - HTML 4.01 Transitional
HTML::Native::Document::HTML401::Frameset - HTML 4.01 Frameset

These can be used as the root element for an HTML::Native document tree.

METHODS

new()

    $doc = HTML::Native::Document::<subclass>->new ( <title> )

Create a new HTML::Native object representing an HTML document. For example:

    my $doc = HTML::Native::Document::HTML401::Strict->new ( "Hello" );

head()

    $head = $doc->head();

Retrieve the HTML::Native object representing the <head> element. For example:

    my $head = $doc->head();    
    push @$head, [ link => { type => "text/css", rel => "Stylesheet",
                             href => "default.css" } ];

body()

    $body = $doc->body();

Retrieve the HTML::Native object representing the <body> element. For example:

    my $body = $doc->body();
    push @$body, [ p => "Hello world" ];

title()

    $title = $doc->title();

Retrieve the HTML::Native object representing the <title> element. For example:

    my $title = $doc->title();
    @$title = ( "Home" );