note 99009 added to class.xmlreader

From: Date: Wed, 21 Jul 2010 22:06:07 +0000
Subject: note 99009 added to class.xmlreader
Groups: php.notes 
Request: Send a blank email to php-notes+get-171030@lists.php.net to get a copy of this message
function xml_read($xml_file){ $xml = new XMLReader(); $xml->open($xml_file); $xml_array = NULL; $xml_protection = NULL; $n = 0; while($xml->read()){ if($xml->nodeType == XMLReader::END_ELEMENT) { $n++; $xml->moveToElement(); } if($xml->nodeType == XMLReader::ELEMENT and !$xml->isEmptyElement){ if (!$xml_protection[$n]) { $xml_protection[$n] = 1; } else { $n++; } $xml_array[$n]['name'] = $xml->name; if($xml->hasAttributes) while($xml->moveToNextAttribute()) $xml_array[$n]['attribute'][$xml->name] = $xml->value; } else if($xml->isEmptyElement) { $xml_array[$n]['name'] = $xml->name; if($xml->hasAttributes) while($xml->moveToNextAttribute()) $xml_array[$n]['attribute'][$xml->name] = $xml->value; $xml_array[$n]['value'] = ""; } else if($xml->nodeType == XMLReader::TEXT) { $xml_array[$n]['value'] = $xml->value; } } $xml->close(); return $xml_array; } /*How to use?*/ $test = xml_read("resim/referanslar.xml"); for ($i=0;count($deneme) > $i;$i++) { echo $test[$i][name] . " " . $test[$i][value] . " " . $test[$i][attribute] . "<br>"; } /*have fun :)*/ ---- Server IP: 69.147.83.197 Probable Submitter: 78.191.182.15 ---- Manual Page -- http://www.php.net/manual/en/class.xmlreader.php Edit -- https://master.php.net/note/edit/99009 Del: integrated -- https://master.php.net/note/delete/99009/integrated Del: useless -- https://master.php.net/note/delete/99009/useless Del: bad code -- https://master.php.net/note/delete/99009/bad+code Del: spam -- https://master.php.net/note/delete/99009/spam Del: non-english -- https://master.php.net/note/delete/99009/non-english Del: in docs -- https://master.php.net/note/delete/99009/in+docs Del: other reasons-- https://master.php.net/note/delete/99009 Reject -- https://master.php.net/note/reject/99009 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171030) next »