note 81852 modified in class.xmlreader by thiago

From: Date: Thu, 13 Nov 2008 12:06:18 +0000
Subject: note 81852 modified in class.xmlreader by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146478@lists.php.net to get a copy of this message
make some modify from Sergey Aikinkulov's note <?php function xml2assoc(&$xml){ $assoc = NULL; $n = 0; while($xml->read()){ if($xml->nodeType == XMLReader::END_ELEMENT) break; if($xml->nodeType == XMLReader::ELEMENT and !$xml->isEmptyElement){ $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->isEmptyElement){ $assoc[$n]['name'] = $xml->name; if($xml->hasAttributes) while($xml->moveToNextAttribute()) $assoc[$n]['atr'][$xml->name] = $xml->value; $assoc[$n]['val'] = ""; $n++; } else if($xml->nodeType == XMLReader::TEXT) $assoc = $xml->value; } return $assoc; } ?> add else if($xml->isEmptyElement) may be some xml has emptyelement --was-- make some modify from Sergey Aikinkulov's note function xml2assoc(&$xml){ $assoc = NULL; $n = 0; while($xml->read()){ if($xml->nodeType == XMLReader::END_ELEMENT) break; if($xml->nodeType == XMLReader::ELEMENT and !$xml->isEmptyElement){ $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->isEmptyElement){ $assoc[$n]['name'] = $xml->name; if($xml->hasAttributes) while($xml->moveToNextAttribute()) $assoc[$n]['atr'][$xml->name] = $xml->value; $assoc[$n]['val'] = ""; $n++; } else if($xml->nodeType == XMLReader::TEXT) $assoc = $xml->value; } return $assoc; } add else if($xml->isEmptyElement) may be some xml has emptyelement http://php.net/manual/en/class.xmlreader.php

« previous php.notes (#146478) next »