Supportnet Computer
Planet of Tech

Supportnet / Forum / Skripte(PHP,ASP,Perl...)

Problem beim XML parsen mit PHP





Frage

Also ich habe folgendes Problem beim parsen einer XML Datei. Es funktioniert eigentlich alles gut soweit, bis auf einen "Unterpunkt". Ich weiß nicht genau wie ich diesen mitparsen kann, bzw. ob dieser nicht schon mit im array ist und ich nur nicht weiß wie ich ihn auslesen kann. das ist meine php datei mit den funktionen: [code] <?php /** * main function for parsing xml file * * @param string $file xml file to parse * @return array result of the parsing */ function MPxmlParse($file) { ini_xml(); //in globals variables $rXMLPARSER = xml_parser_create(); xml_parser_set_option($rXMLPARSER, XML_OPTION_CASE_FOLDING, 1); xml_set_element_handler($rXMLPARSER, ´start_element´, ´close_element´); xml_set_character_data_handler($rXMLPARSER,´character_data´); $fp = fopen($file, ´r´); while($sXmlStream = fread($fp, 4096)) { if (!xml_parse($rXMLPARSER, $sXmlStream, feof($fp))) { die(´Error parsing xml file´); } } fclose($fp); $aRet[´ressources´] = $GLOBALS[´aXmlTotalElements´]; $aRet[´infos´] = $GLOBALS[´xmlInfos´]; return $aRet; } /** * start_element * @private */ function start_element($parser, $name, $attrs=´´) { $name = strtolower(trim($name)); $GLOBALS[´sXmlactualElement´] = $name; if(in_array($name, $GLOBALS[aSpecialElements])) { $GLOBALS[´xmlElementCpt´]++; }elseif($name == ´drt´) { $GLOBALS[´aXmlAttrs´] = $attrs; } } // end func start_element /** * close_element * @private */ function close_element($parser, $name, $attrs=´´) { $name = strtolower(trim($name)); if($name == ´ressource´ && $GLOBALS[´sXmlactualElement´] != ´file´) { $GLOBALS[´xmlElementCpt´]++; } } // end func close_element /** * character_data * @private */ function character_data($parser, $data=´´) { if($GLOBALS[´sXmlactualElement´] != ´ressource´ && $GLOBALS[´sXmlactualElement´] != ´drt´ && !in_array($GLOBALS[´sXmlactualElement´], $GLOBALS[´aSpecialElements´]) ) { $GLOBALS[´aXmlTotalElements´][$GLOBALS[´xmlElementCpt´]][$GLOBALS[´sXmlactualElement´]].= trim($data); }elseif($GLOBALS[´sXmlactualElement´] == ´drt´) { $GLOBALS[´xmlInfos´] = $GLOBALS[´aXmlAttrs´]; }else{ if($GLOBALS[´sXmlactualElement´] != ´ressource´) { $GLOBALS[´xmlInfos´][$GLOBALS[´sXmlactualElement´]].= trim($data); } } } // end func character_data /** * initialize xml variables */ function ini_xml() { $GLOBALS[´aXmlTotalElements´] = array(); $GLOBALS[´sXmlactualElement´] = ´´; $GLOBALS[´xmlElementCpt´] = 0; $GLOBALS[´aXmlAttrs´] = array(); $GLOBALS[´xmlInfos´] = array(); $GLOBALS[´aSpecialElements´] = array(´ressource´,´first_url´,´last_url´,´next_url´,´prev_url´); } // end func ini_xml ?> [/code] die Ausgabe habe ich dann so realisiert: [code] $sFile = ´http://mpxml.mediaplazza.com/xml_act.php?a=www&t=26&l=DE&c=DE&h=1&game=148&act=GAMESDETAIL´; $aArray = MPxmlParse($sFile); // parsing of the file $aRess = $aArray[´ressources´]; //array with all content $aInfos = $aArray[´infos´]; //array with all informations (max_page, total_results...) foreach ($aRess as $aInfo) { $lib = trim(stripslashes($aInfo[´lib´])); if (strlen($lib) > 0){ echo $aInfo[´screenbox´]; //funktioniert echo $aInfo[´screenshots´]; // funktioniert nicht } } [/code] meine frage ist jetzt, wie muss ich die parse datei erweitern, um an die 6 screenshots zu kommen??? ich bin leider noch nicht so bewandert in xml und habe deshalb keine idee mehr... der pfad zur xml datei steht im sourcecode.

Antwort von



Ich möchte kostenlos eine Frage an die Mitglieder stellen:


Ähnliche Themen:


Suche in allen vorhandenen Beiträgen: