php - SAX-based parser not seeking content -
php - SAX-based parser not seeking content -
i trying implement sax based parser somehow recognizes start of element , end, content not provided in logs. variable holding xml filled correctly, checked through simple log. here code:
<?php function startelementhandler($parser, $name, $attribs) { if($name == "id"){ $id = true; } } function endelementhandler($parser,$name){ $id = false; } function characterdatahandler($parser,$data){ if($id == true){ echo $data; } } global $id; $id = false; $parser = xml_parser_create(); xml_set_element_handler($parser, "startelementhandler","endelementhandler"); xml_set_character_data_handler($parser,"characterdatahandler"); $xml = file_get_contents("http://itunes.apple.com/de/rss/topfreeapplications/limit=100/xml"); xml_parse($parser,$xml); //xml_parser_free($parser); ?>
any suggestion how recieve content? maybe missing unusual not aware of @ moment. best regards tim
per comment, $id
never becomes true. maybe want attribs have id , not name of element. example, if have xml
<div id="x"> blah </div>
you
$name="div", $attribs={"id":"x"}
(this came out bit of php-python, hope point)
is bug?
according http://www.phpcatalyst.com/php-compare-strings.php should compare strings using ===
. bug?
php xml parsing sax
Comments
Post a Comment