note 86807 modified in function.simplexml-load-string by danbrown
| From: | danbrown@php.net | Date: | Fri, 14 Nov 2008 18:26:56 +0000 |
| Subject: | note 86807 modified in function.simplexml-load-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146558@lists.php.net to get a copy of this message | ||
How about a recursive function to reduce the xml hard-coding in your apps? Here is my simple
listing routine as an example:
<?php
function list_xml($str) {
$root = simplexml_load_string($str);
list_node($root);
}
function list_node($node) {
foreach ($node as $element) {
echo $element. "\n";
if ($element->children()) {
echo "<br/>";
list_node($element);
}
}
}
?>
--was--
How about a recursive function to reduce the xml hard-coding in your apps? Here is my simple
listing routine as an example:
<?php
function list_xml($str) {
$root = simplexml_load_string($str);
list_node($root);
}
function list_node($node) {
foreach ($node as $element) {
echo $element. "\n";
if ($element->children()) {
list_node($element);
echo "<br/>";
}
}
}
?>
http://php.net/manual/en/function.simplexml-load-string.php