|
-
Feb 8th, 2006, 01:49 AM
#1
Thread Starter
PowerPoster
XML Convertor broken for some reason...
Grumble, ok, here comes a pile of code that I picked up from PHP.net
PHP Code:
function &last(&$array) {
error_reporting(E_ALL);
if (!count($array)) return null;
end($array);
return $array[key($array)];
}
function myParseXML(&$vals, &$dom, &$lev) {
error_reporting(E_ALL);
do {
$curr = current($vals);
$lev = $curr['level'];
switch ($curr['type']) {
case 'open':
if (isset($dom[$curr['tag']])) {
$tmp = $dom[$curr['tag']];
if (!@$tmp['__multi'])
$dom[$curr['tag']] = array('__multi' => true, $tmp);
array_push($dom[$curr['tag']], array());
$new =& last($dom[$curr['tag']]);
} else {
$dom[$curr['tag']] = array();
$new =& $dom[$curr['tag']];
}
next($vals);
//REMOVED A Pointer
myParseXML($vals, $new, $lev);
break;
case 'cdata':
break;
case 'complete':
if (!isset($dom[$curr['tag']]))
$dom[$curr['tag']] = $curr['value'];
else {
if (is_array($dom[$curr['tag']]))
array_push($dom[$curr['tag']] , $curr['value']);
else
array_push($dom[$curr['tag']] = array($dom[$curr['tag']]) , $curr['value']);
}
break;
case 'close':
return;
}
} while (next($vals)!==FALSE);
}
function MyXMLtoArray($XML) {
error_reporting(E_ALL);
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $XML, $vals);
xml_parser_free($xml_parser);
reset($vals);
$dom = array(); $lev = 0;
myParseXML($vals, $dom, $lev);
return $dom;
}
MyXMLToArray is the starting point, you pass it a string containing XML and its supposed to return a nice array that I can loop with. This code was working perfectly last year, and is now stuffed. :\ Any ideas as to why? It simple returns a blank page.. I've been using comments and I believe the cause is MyXMLParse, but not sure why...
If no-one can figure out what its doing wrong, perhaps some alternative code that works well... going to be a complete pain in the arse to re-write my script though if I have to go down that route
Last edited by Pc_Madness; Feb 8th, 2006 at 02:05 AM.
Don't Rate my posts.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|