note 83929 added to class.xmlreader

From: Date: Thu, 19 Jun 2008 10:51:39 +0000
Subject: note 83929 added to class.xmlreader
Groups: php.notes 
Request: Send a blank email to php-notes+get-140580@lists.php.net to get a copy of this message
Next version xml2assoc with some improve fixes: - no doubled data - no buffer arrays <?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; while($xml->read()){ switch ($xml->nodeType) { case XMLReader::END_ELEMENT: return $assoc; case XMLReader::ELEMENT: $assoc[$xml->name][] = array('value' => $xml->isEmptyElement ? '' : xml2assoc($xml)); if($xml->hasAttributes){ $el =& $assoc[$xml->name][count($assoc[$xml->name]) - 1]; while($xml->moveToNextAttribute()) $el['attributes'][$xml->name] = $xml->value; } break; case XMLReader::TEXT: case XMLReader::CDATA: $assoc .= $xml->value; } } return $assoc; } ?> ---- Server IP: 195.54.192.44 Probable Submitter: 127.0.0.1 ---- Manual Page -- http://www.php.net/manual/en/class.xmlreader.php Edit -- https://master.php.net/note/edit/83929 Del: integrated -- https://master.php.net/note/delete/83929/integrated Del: useless -- https://master.php.net/note/delete/83929/useless Del: bad code -- https://master.php.net/note/delete/83929/bad+code Del: spam -- https://master.php.net/note/delete/83929/spam Del: non-english -- https://master.php.net/note/delete/83929/non-english Del: in docs -- https://master.php.net/note/delete/83929/in+docs Del: other reasons-- https://master.php.net/note/delete/83929 Reject -- https://master.php.net/note/reject/83929 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140580) next »