Hallo,
ich bin gerade dabei mit xml parsing rum zuexperimentieren und habe natürlich Probleme damit... Es scheint so, als geht er den "PATH" zweimal durch. Ich habe das mit ner 1 im Output gekennzeichnet. Weiß von Euch jmd worans liegen kann?
phh code:
	
XML File:
	HTML Output:
	
		
					ich bin gerade dabei mit xml parsing rum zuexperimentieren und habe natürlich Probleme damit... Es scheint so, als geht er den "PATH" zweimal durch. Ich habe das mit ner 1 im Output gekennzeichnet. Weiß von Euch jmd worans liegen kann?
phh code:
PHP-Code:
	
	
class RSSParser {
   var $inside_bereich = false;
   var $name= "";
   var $inside_anwendung = false;
   var $tag = "";
   var $title = "";
   var $path = "";
   function startElement($parser, $tagName, $attrs) {
       if ($this->inside_bereich) {
           $this->tag = $tagName;
       } elseif ($tagName == "BEREICH") {
           $this->inside_bereich = true;
       }
       if ($this->inside_anwendung) {
           $this->tag = $tagName;
       } elseif ($tagName == "ANWENDUNG") {
           $this->inside_anwendung = true;
       }
   }
   function endElement($parser, $tagName) {
       if ($tagName == "ANWENDUNG") {
           $this->inside_anwendung = false;
       }
       if ($tagName == "BEREICH") {
           $this->inside_bereich = false;
       }
   }
   function characterData($parser, $data) {
       if ($this->inside_bereich) {
           if ($this->tag == "NAME") {
                $this->name .= $data;
                printf("<p><b>%s</b></p>",
                trim($this->name));
                $this->name = "";
                }
       }
       if ($this->inside_anwendung) {
           switch ($this->tag) {
               case "TITLE":
               $this->title .= $data;
               break;
               case "PATH":
               $this->path .= $data;
               printf("<a href='%s'>%s1</a><br>",
               trim($this->path),htmlspecialchars(trim($this->title)));
               $this->title = "";
               $this->path = "";
               break;
           }
       }
   }
}
$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();
xml_set_object($xml_parser,&$rss_parser);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("data/menu.xml","r")
   or die("Error reading XML data.");
while ($data = fread($fp, 4096))
   xml_parse($xml_parser, $data, feof($fp))
       or die(sprintf("XML error: %s at line %d",
           xml_error_string(xml_get_error_code($xml_parser)),
           xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser); 
Code:
	
	<menu> <dienst> <bereich> <name>Mail</name> <anwendung> <title>Quarantaene</title> <path>/var/www/quarantine</path> <auswahl> <standort> Bremen </standort> <standort> Hamburg </standort> <standort> Luebeck </standort> </auswahl> </anwendung> <anwendung> <title>Viren</title> <path>/var/www/viren</path> </anwendung> <anwendung> <title>Mailconf</title> <path>/var/www/mailconf/</path> <auswahl> <standort> Bremen </standort> <standort> Hamburg </standort> <standort> Luebeck </standort> </auswahl> </anwendung> </bereich> <bereich> <name>Proxy</name> <anwendung> <title>Konfiguration</title> <path>/var/www/proxyconf/</path> <auswahl> <standort> Bremen </standort> <standort> Hamburg </standort> <standort> Luebeck </standort> </auswahl> </anwendung> <anwendung> <title>Logdateien</title> <path>/var/www/proxylogs/</path> <auswahl> <standort> Bremen </standort> <standort> Hamburg </standort> <standort> Luebeck </standort> </auswahl> </anwendung> </bereich> </dienst> </menu>
			
			
				Mail
Quarantaene1
1
Viren1
1
Mailconf1
1
Proxy
Konfiguration1
1
Logdateien1
1
	Quarantaene1
1
Viren1
1
Mailconf1
1
Proxy
Konfiguration1
1
Logdateien1
1
EDIT: 
code+quote.tags by Abraxax
 
          
 XML OO parsen
									
									
									XML OO parsen
								


Kommentar