reiniger Posted May 12, 2009 Report Share Posted May 12, 2009 Sveicināti. Esmu iesācējs lietā ar XML. Man nepieciešams nolasīt xml no (http://esports.lv/teniss/latvijas_sportisti/rss) Mans kods: <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <? $xml_file = "http://esports.lv/teniss/latvijas_sportisti/rss"; if(!($fp = @fopen($xml_file, "r"))) die ("<H4>couldn't open menu file xml</H4>"); # menu array $folderList = Array(); $position = 0; // *************** // xml parser // *************** $xml_current_tag_state = ""; function startElementHandler( $parser, $element_name, $element_attribs){ global $folderList, $xml_current_tag_state, $item_position, $position; if($element_name == "ITEM"){ $position++; $xml_current_tag_state = $element_name; $folderList[$position] = array(); } else { $xml_current_tag_state = $element_name; } } function endElementHandler($parser, $element_name){ global $folderList, $xml_current_tag_state; $xml_current_tag_state = ""; } function characterDataHandler($parser, $data){ global $folderList, $xml_current_tag_state, $item_position, $position; if($xml_current_tag_state == "") return; $data = trim($data); if($xml_current_tag_state == "ITEM"){ } else if($xml_current_tag_state == "TITLE" && !empty($data)){ $folderList[$position]["TITLE"] = ($data); }else if($xml_current_tag_state == "LINK" && !empty($data)){ $folderList[$position]["LINK"] = ($data); else if($xml_current_tag_state == "DESCRIPTION" && !empty($data)){ $folderList[$position]["DESCRIPTION"] = ($data); } else if($xml_current_tag_state == "ID" && !empty($data)){ if(empty($folderList[$position]["ID"])){ $folderList[$position]["ID"] = urldecode($data); } } } # create parser... if( !($xml_parser = xml_parser_create())) die("Couldn't create the parser"); xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler"); xml_set_character_data_handler($xml_parser, "characterDataHandler"); # start parsin file... while($data = @fread($fp, 8192)){ xml_parse($xml_parser, $data, feof($fp)); } # free parser xml_parser_free($xml_parser); array_splice($folderList,0,1); if(count($folderList) == 0) { echo "Problems reading xml file"; } else { ?> <? foreach($folderList as $key => $value){ print "<b>".$value['TITLE']."</b><br />"; print $value['DESCRIPTION']."<br />"; print "<a href='".$value['LINK']."'>".$value['LINK']."</a><br />"; } ?> <? } ?> Viss <title> un <link> izdrukajas viss kartiba bet <DESCRIPTION> izdrukajas nevienmēr viss. Biezi vien izdrukājas tikai no visa raksta tikai kadi daži pēdējie vārdi. Piemērs. No esports: Latvijas tenisists Andis Juška izcīnījis pārliecinošu uzvaru Korejas pilsētas Busanas "Challneger" vienspēļu turnīra pirmajā kārtā. Ar 6:2, 6:2 viņš pārspēja japāni Hiroki Kondo, bet nākamo spēli aizvadīs pret turnīra trešo raketi Florianu Maieru no Vācijas. mans rezultāts: vienspēļu turnīra pirmajā kārtā. Ar 6:2, 6:2 viņš pārspēja japāni Hiroki Kondo, bet nākamo spēli aizvadīs pret turnīra trešo raketi Florianu Maieru no Vācijas. Kas varētu būt par problēmu? Quote Link to comment Share on other sites More sharing options...
marrtins Posted May 12, 2009 Report Share Posted May 12, 2009 Varbūt tam parserim nepatīk pēdiņas un citi speciālie simboli? P.S. Sen bij laiks upgrade uz PHP5 ;) Quote Link to comment Share on other sites More sharing options...
reiniger Posted May 12, 2009 Author Report Share Posted May 12, 2009 (edited) Atrisināju šo problēmu ar: if($xml_current_tag_state == "DESCRIPTION" && !empty($data)){ $folderList[$position]["DESCRIPTION"][] = $data; } ielasot to masiva un izdrukaju ar for($i=0; $i<count($value['DESCRIPTION']);$i++) echo $value['DESCRIPTION'][$i]; Un problēma atrisināta :) Sen bij laiks upgrade uz PHP5 ;) pilnībā piekrītu bet tas jau nav mans serveris uz kura stāv lapa kuru man japarediģē... :) Edited May 12, 2009 by reiniger Quote Link to comment Share on other sites More sharing options...
reiniger Posted May 12, 2009 Author Report Share Posted May 12, 2009 Šis ir no xml: <enclosure url="http://images.esports.lv/220x162/galleries/romualds_vambuts/2896/3456_dsc0982.jpg" type="image/jpeg" /> Kā es varu iegūt šo URL? ja būtu <enclosure >http://images.esports.lv/220x162/galleries/romualds_vambuts/2896/3456_dsc0982.jpg</enclosure > tad ar if($xml_current_tag_state == "enclosure" && !empty($data)){ $folderList[$position]["enclosure"] = $data; } Butu pateicigs par idejām. Quote Link to comment Share on other sites More sharing options...
marrtins Posted May 13, 2009 Report Share Posted May 13, 2009 Varbūt jāizmanto tas $element_attribs ? Quote Link to comment Share on other sites More sharing options...
reiniger Posted May 17, 2009 Author Report Share Posted May 17, 2009 Kaut kā galīgi neizdodas! Kādam ir idejas? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.