note 89845 modified in function.simplexml-element-children by danbrown
| From: | danbrown@php.net | 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 . "<" . $han->getName() . warpAttributes(
$han->attributes() ) . "> " . $han . " </" .
$han->getName() . "><br />";
}
$ret = $preffix . "<" . $han->getName() . warpAttributes( $han->attributes()
) . "><br />";
foreach( $han->children() as $key => $child )
{
$ret .= RecursiveXML($child , $preffix . "|-- " );
}
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 . "<" . $han->getName() . warpAttributes(
$han->attributes() ) . "> " . $han . " </" .
$han->getName() . "><br />";
}
$ret = $preffix . "<" . $han->getName() . warpAttributes( $han->attributes()
) . "><br />";
foreach( $han->children() as $key => $child )
{
$ret .= RecursiveXML($child , $preffix . "|-- " );
}
return $ret;
}
?>
enjoy :)
http://php.net/manual/en/function.simplexml-element-children.php