Source for file HTMLtoXHTML.php
Documentation is available at HTMLtoXHTML.php
* $Id: HTMLtoXHTML.php,v 1.3 2004/06/02 14:33:38 hfuecks Exp $
* Demonstrates conversion of HTML to XHTML
require_once('XML/HTMLSax3.php');
class HTMLtoXHTMLHandler {
function HTMLtoXHTMLHandler (){
// Handles the writing of attributes - called from $this->openHandler()
function writeAttrs ($attrs) {
foreach ( $attrs as $name => $value ) {
if ( $name == 'checked' ) {
$this->xhtml.= ' checked="checked"';
} else if ( $name == 'selected' ) {
$this->xhtml.= ' selected="selected"';
$this->xhtml.= ' '. $name. '="'. $value. '"';
function openHandler (& $parser,$name,$attrs) {
if ( (isset ( $attrs['id'] ) && $attrs['id'] == 'title') || $name == 'title' )
$this->xhtml.= "<br />\n";
$this->xhtml.= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"eng\">\n";
if ( $this->pCounter != 0 ) {
$this->writeAttrs ($attrs);
function closeHandler (& $parser,$name) {
if ($name == 'body' && $this->pCounter != 0 )
$this->xhtml.= "</". $name. ">\n";
// Character data handler
function dataHandler (& $parser,$data) {
$this->xhtml.= 'This is XHTML 1.0';
function escapeHandler (& $parser,$data) {
if ( $data == 'doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"' )
$this->xhtml.= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
// Return the XHTML document
// Instantiate the handler
$handler= & new HTMLtoXHTMLHandler ();
// Instantiate the parser
// Register the handler with the parser
$parser->set_object ($handler);
$parser->set_element_handler ('openHandler','closeHandler');
$parser->set_data_handler ('dataHandler');
$parser->set_escape_handler ('escapeHandler');
echo ( $handler->getXHTML () );
Documentation generated on Mon, 11 Mar 2019 10:17:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|