note 81551 deleted from class.xmlreader by thiago

From: Date: Wed, 12 Nov 2008 13:34:26 +0000
Subject: note 81551 deleted from class.xmlreader by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146427@lists.php.net to get a copy of this message
Note Submitter: Sergey Aikinkulov ---- <?php /* Read XML structure to associative array -- Using: $xml = new XMLReader(); $xml->open([XML file]); $assoc = xml2assoc($xml); $xml->close(); */ function xml2assoc(&$xml){ $assoc = NULL; $n = 0; while($xml->read()){ if($xml->nodeType == XMLReader::END_ELEMENT) break; if($xml->nodeType == XMLReader::ELEMENT){ $assoc[$n]['name'] = $xml->name; if($xml->hasAttributes) while($xml->moveToNextAttribute()) $assoc[$n]['atr'][$xml->name] = $xml->value; $assoc[$n]['val'] = xml2assoc($xml); $n++; } else if($xml->nodeType == XMLReader::TEXT) $assoc = $xml->value; } return $assoc; } ?>

« previous php.notes (#146427) next »