15.2 The file handlers

The itools.xhtml package provides a file handler for XHTML documents. It is not much different from the handler for XML files (see Section 16.3).

First, if we create a new XHTML handler from scratch it will be correctly initialized:

    >>> from itools.html import XHTMLFile
    >>> doc = XHTMLFile(title='Hello World')
    >>> print doc.to_str()
    <?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>
        <meta http-equiv="Content-Type" content="..."/>

        <title>Hello World</title>
      </head>
      <body></body>
    </html>

Second, we have a couple of handy methods to get the head and the body of the document:

    >>> print doc.get_head().get_content()
    <meta http-equiv="Content-Type" content="..."/>
    <title>Hello World</title>
    >>>
    >>> print doc.get_body().get_content()

The HTML handlers

The HTML handler is very much similar to the XHTML handler.