X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=blobdiff_plain;ds=sidebyside;f=www%2Fecrire%2Finc%2Fsimplexml_to_array.php;h=3e572e3570ef00db54c9a2773864d1722194bc26;hb=dae7b78d26d32fb23e8c524f795bbaf40e685c6a;hp=142b858e7e66489dec395d0647b06d6b6fcf59e2;hpb=52cf8ed924d5dcd0c28dde4b6c3196be6ec2d4f7;p=ptitvelo%2Fweb%2Fwww.git diff --git a/www/ecrire/inc/simplexml_to_array.php b/www/ecrire/inc/simplexml_to_array.php index 142b858..3e572e3 100644 --- a/www/ecrire/inc/simplexml_to_array.php +++ b/www/ecrire/inc/simplexml_to_array.php @@ -1,26 +1,58 @@ @xmlObjToArr($u, $utiliser_namespace)); +} /** * Transforme un objet SimpleXML en tableau PHP + * http://www.php.net/manual/pt_BR/book.simplexml.php#108688 + * xaviered at gmail dot com 17-May-2012 07:00 * * @param object $obj + * @param bool $utiliser_namespace * @return array **/ -// http://www.php.net/manual/pt_BR/book.simplexml.php#108688 -// xaviered at gmail dot com 17-May-2012 07:00 -function inc_simplexml_to_array_dist($obj, $utiliser_namespace='false') { +function xmlObjToArr($obj, $utiliser_namespace=false) { $tableau = array(); // Cette fonction getDocNamespaces() est longue sur de gros xml. On permet donc // de l'activer ou pas suivant le contenu supposé du XML if (is_object($obj)) { - if ($utiliser_namespace) - $namespace = $obj->getDocNamespaces(true); - $namespace[NULL] = NULL; + if (is_array($utiliser_namespace)){ + $namespace = $utiliser_namespace; + } + else { + if ($utiliser_namespace) + $namespace = $obj->getDocNamespaces(true); + $namespace[NULL] = NULL; + } $name = strtolower((string)$obj->getName()); $text = trim((string)$obj); @@ -51,16 +83,19 @@ function inc_simplexml_to_array_dist($obj, $utiliser_namespace='false') { if( !empty($ns) ) { $childName = $ns.':'.$childName; } - $children[$childName][] = inc_simplexml_to_array_dist($child); + $children[$childName][] = xmlObjToArr($child, $namespace); } } $tableau = array( 'name'=>$name, - 'text'=>$text, - 'attributes'=>$attributes, - 'children'=>$children ); + if ($text) + $tableau['text'] = $text; + if ($attributes) + $tableau['attributes'] = $attributes; + if ($children) + $tableau['children'] = $children; } return $tableau;