note 89845 modified in function.simplexml-element-children by danbrown

From: Date: Wed, 16 Sep 2009 15:32:47 +0000
Subject: note 89845 modified in function.simplexml-element-children by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160688@lists.php.net to get a copy of this message
I done a very nice function to run over the XML element recursivly with SimpleXML, and print it on the screen here it is: <?php $xml_han = new SimpleXMLElement( "data.xml", null, true ); print RecursiveXML( $xml_han ); function RecursiveXML( SimpleXMLElement $han, $preffix = "") { if( count( $han->children() ) < 1 ) { return $preffix . "&lt;" . $han->getName() . warpAttributes( $han->attributes() ) . "&gt;&nbsp;" . $han . "&nbsp;&lt;/" . $han->getName() . "&gt;<br />"; } $ret = $preffix . "&lt;" . $han->getName() . warpAttributes( $han->attributes() ) . "&gt;<br />"; foreach( $han->children() as $key => $child ) { $ret .= RecursiveXML($child , $preffix . "|--&nbsp;&nbsp;&nbsp;" ); } return $ret; } ?> enjoy :) --was-- I done a very nice function to run over the XML element recursivly with SimpleXML, and print it on the screen here it is: <?php $xml_han = new SimpleXMLElement( "data.xml", null, true ); print RecursiveXML( $xml_han ); function RecursiveXML( SimpleXMLElement $han, $preffix = "") { if( count( $han->children() ) < 1 ) { return $preffix . "&lt;" . $han->getName() . warpAttributes( $han->attributes() ) . "&gt;&nbsp;" . $han . "&nbsp;&lt;/" . $han->getName() . "&gt;<br />"; } $ret = $preffix . "&lt;" . $han->getName() . warpAttributes( $han->attributes() ) . "&gt;<br />"; foreach( $han->children() as $key => $child ) { $ret .= RecursiveXML($child , $preffix . "|--&nbsp;&nbsp;&nbsp;" ); } return $ret; } ?> enjoy :) http://php.net/manual/en/function.simplexml-element-children.php

« previous php.notes (#160688) next »