Hallo zusammen!
Ich habe für eine HP eine Navigation mittels XML erstellt.
Lokal habe ich PHP 5 laufen und habe deshalb folgendes probiert:
e<?php $filename = „navi.xml“;
if(file_exists($filename) && ISSET($select))
{
if(!($xmlparser = xml_parser_create()))
{
die(„Cannot create parser“);
}
$xml = simplexml_load_file($filename);
foreach($xml->menuitem as $key => $value) /* alle menu-eintraege durchgehen */
{
$name = $value->name[0];
$label = $value->label[0];
$link = $value->link[0];
?>
{ ?\> <?php }
else { ?\> <?php } ?> <?php }
} ?\> Da der Server, der mir zur Verfügung steht nur PHP 4 unterstützt wollte ich das anders lösen und habe gegoogelt. Die Suche brachte folgendes ein: [http://www.developertutorials.com/tutorials/php/pars...](http://www.developertutorials.com/tutorials/php/parsing-xml-using-php4-050816/page9.html) Nach dem Abwandeln des Codes habe ich folgendes: <?php $current = "";
$select = "home"; function start\_tag($parser, $name, $attribs) { global $current; $current = $name; if($name == "NAVIGATION") { echo ' '; } if($name == "MENUITEM") { echo ' '; } } function end\_tag($parser, $name) { if($name == "NAVIGATION") { echo ' '; } if($name == "MENUITEM") { echo ''; } } function tag\_contents($parser, $data) { global $current; global $select; if($current == "NAME") { if($select == $data) { echo ''; } if($current == "LABEL") { echo $data.''; } } function parseXML($filename) { if(!($xmlparser = xml\_parser\_create())) { die("Cannot create parser"); } xml\_set\_element\_handler($xmlparser, "start\_tag", "end\_tag"); xml\_set\_character\_data\_handler($xmlparser, "tag\_contents"); if(!($fp = fopen($filename, "r"))) { die("cannot open ".$filename); } while($data = fread($fp, 4096)) { $data = eregi\_replace("\>"."[[:space:]]+"." Es wird komischerweise die Methode tag\_contents() mehrmals pro Element aufgerufen. Mein XML-File: <?xml version="1.0" encoding="utf-8" ?>homeindex.php
home
aboutabout.php
Über uns
projectproject.php
Projekte
contactcontact.php
Kontakt
linkslinks.php
Links
aktuellaktuell.php
Aktuelles
Könnt Ihr mir sagen welchen Fehler ich begehe?
Wenn ihr andere Lösungen für PHP 4 kennt, rührt euch bitte ebenfalls
Gruß und gute Nacht,
pheax