<html>
<head>
</head>
<body bgcolor="white">
<link type="text/css" rel="stylesheet" title="Default"
href="../styles/main.css">
<title>Gjestebok</title>
<?
//This takes a XML-file and parses it to HTML.
//Modify it for your needs
//Written by Sindre Mathisen
// data file
$file = "mynews.xml";
$startTags = array(
"GJESTEBOK" => "<h2>Velkommen til min gjestebok!</h2>",
"MELDING" => "<table border=1 width=500>",
"BESKJED" => "<tr><td width=50><strong>Melding: </strong></td><td>",
"NAVN" => "<tr><td width=50><strong>Navn: </strong></td><td>",
"EMAIL" => "<tr><td width=50><strong>Mail: </strong></td><td><a href=\"mailto:",
);
// close tags opened above
$endTags = array(
"NAVN" => "</td></tr>",
"BESKJED" => "</td></tr>",
"EMAIL" => "\"</a>Mail</td></tr>",
"MELDING" => "</table><br>",
);
function startElement($parser, $name, $attrs) {
global $startTags;
// if tag exists as key, print value
if ($startTags[$name]) { echo $startTags[$name]; }
}
function endElement($parser, $name) {
global $endTags;
if ($endTags[$name]) { echo $endTags[$name]; }
}
// process data between tags
function characterData($parser, $data) {
echo $data;
}
// initialize parser
$xml_parser = xml_parser_create();
// set callback functions
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
// open XML file
if (!($fp = fopen($file, "r")))
{
die("Cannot locate XML data file: $file");
}
// read and parse data
while ($data = fread($fp, 4096))
{
// error handler
if (!xml_parse($xml_parser, $data, feof($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)));
}
}
// clean up
xml_parser_free($xml_parser);
?>
<p>Skriv et <a href="insert.php">nytt</a> innlegg i gjestebok.</p>
<p>Denne siden er parset fra XML til PHP ved hjelp av "The SinSoft Parser"</p>
</body>
</html>