<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
  <HEAD>
<TITLE>PHP-XML Demo: XML to HTML</TITLE>
  </HEAD>
  <BODY>
    <H1>PHP-XML Demo: XML to HTML</H1>
This is a slightly modified example from the XML manual:

<ul>
<li>Different data
<li>endElementHandle(parser, name) function fixed!)
</ul>

<p>
Here we go:
<hr>
<?
$file 
"choco-chip.xml";

// Put the key in upper case !
$map_array = array(
           
"LIST"        => "list",
           
"RECIPE"      => "hr",
           
"RECIPE_NAME" => "H1",
           
"AUTHOR"      => "strong",
           
"MEAL"        => "H2",
           
"COURSE"      => "H3",
           
"INGREDIENTS" => "ol",
           
"ITEM"        => "li",
           
"DIRECTIONS"  => "p"
           
);

function 
startElement($parser$name$attrs)
{
    global 
$map_array;
    
// print "DEBUG: $name <br>";
    
if ($htmltag $map_array[$name]) {
        print 
"<$htmltag>";
    }
}

function 
endElement($parser$name)
{
    global 
$map_array;
    if (
$htmltag $map_array[$name]) {
        print 
"</$htmltag>";
    }
}

function 
characterData($parser$data)
{
    print 
$data;
}

$xml_parser xml_parser_create();

// use case-folding so we are sure to find the tag in $map_array ;)
xml_parser_set_option($xml_parserXML_OPTION_CASE_FOLDINGtrue);
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");

if (!(
$fp fopen($file"r"))) {
  die(
"could not open XML input");
}

while (
$data fread($fp4096)) {
  if (!
xml_parse($xml_parser$datafeof($fp))) {
    die(
sprintf("XML error: %s at line %d",
        
xml_error_string(xml_get_error_code($xml_parser)),
        
xml_get_current_line_number($xml_parser)));
  }
}

xml_parser_free($xml_parser);

?>

<hr>


  <ADDRESS>
    <A NAME="Signature"
       HREF="http://tecfa.unige.ch/tecfa-people/schneider.html">D.K.S.</A>
  </ADDRESS>
  </BODY>
</HTML>