chizijs Posted February 28, 2010 Report Share Posted February 28, 2010 Tātad man vajag ar php palīdzibu izlasīt xml faila saturu, bet kaut kas neiet, kad ieeju adresē kur atrodās tas php kods izmēt visu xml faila saturu. Kas varētu būt par problēmu? XML Kods <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <country>Latvia</country> <city>Rīga</city> <other>cits</other> <other2>cits2</other> <other3>cits3</other> PHP Kods $parser=xml_parser_create(); function start($parser,$element_name,$element_attrs) { switch($element_name) { case "country": echo "Valsts: "; break; case "city": echo "Pilsēta: "; } } function stop($parser,$element_name) { echo "<br />"; } function char($parser,$data) { echo $data; } xml_set_element_handler($parser,"start","stop"); xml_set_character_data_handler($parser,"char"); $fp=fopen("fails.xml","r"); while ($data=fread($fp,4096)) { xml_parse($parser,$data,feof($fp)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); } xml_parser_free($parser); Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted February 28, 2010 Report Share Posted February 28, 2010 (edited) Izmanto SimpleXML - ar to būs daudz ērtāk. (pie nosacījuma, ja tev ir PHP5) + ja tev viss XML ir vienā līmenī, tad apdomā vai vispār ir vērts izmantot XML. Edited February 28, 2010 by rATRIJS Quote Link to comment Share on other sites More sharing options...
chizijs Posted February 28, 2010 Author Report Share Posted February 28, 2010 <?php $xml = "fails.xml"; $xmlget = simplexml_load_string($xml); echo $xml->city; ?> Tagad vispār rāda tikai baltu lapu? Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted February 28, 2010 Report Share Posted February 28, 2010 (edited) Ieslēdz error reporting... Un tad: 1) paskaties ko dara f-ja simplexml_load_string() 2) paskaties ko tu izvadi P.S. priekšā es neteikšu Edited February 28, 2010 by rATRIJS 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.