note 71074 added to function.xml-parse-into-struct

From: Date: Fri, 10 Nov 2006 19:15:38 +0000
Subject: note 71074 added to function.xml-parse-into-struct
Groups: php.notes 
Request: Send a blank email to php-notes+get-119592@lists.php.net to get a copy of this message
I'm currently using this parser and it's working the way I want it to, but it has a little glitch and I was hoping maybe someone can let me know why. Here's the parser and use for example purposes the following input: $xml_response = '<?xml version="1.0" encoding="UTF-8"?> <test> <item>First Item</item> <item>Second Item</item> </test>' $xml_parser = xml_parser_create(); xml_parse_into_struct($xml_parser, $xml_response, $vals, $index); xml_parser_free($xml_parser); $params = array(); $level = array(); foreach ($vals as $xml_elem) { if ($xml_elem['type'] == 'open') { if (array_key_exists('attributes',$xml_elem)) { list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']); } else { $level[$xml_elem['level']] = $xml_elem['tag']; } } if ($xml_elem['type'] == 'complete') { $start_level = 1; $php_stmt = '$params'; while($start_level < $xml_elem['level']) { $php_stmt .= '[$level['.$start_level.']]'; $start_level++; } $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];'; eval($php_stmt); } } echo "<pre>"; print_r ($params); echo "</pre>"; At the output, only the last <item> shows (i.e.Second Item). The first one is lost. What should I change so it keeps ALL <item> tags. ---- Server IP: 66.207.199.35 Probable Submitter: 64.229.141.99 ---- Manual Page -- http://www.php.net/manual/en/function.xml-parse-into-struct.php Edit -- https://master.php.net/note/edit/71074 Del: integrated -- https://master.php.net/note/delete/71074/integrated Del: useless -- https://master.php.net/note/delete/71074/useless Del: bad code -- https://master.php.net/note/delete/71074/bad+code Del: spam -- https://master.php.net/note/delete/71074/spam Del: non-english -- https://master.php.net/note/delete/71074/non-english Del: in docs -- https://master.php.net/note/delete/71074/in+docs Del: other reasons-- https://master.php.net/note/delete/71074 Reject -- https://master.php.net/note/reject/71074 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119592) next »