note 101330 added to simplexmlelement.children
| From: | coldshine1 at rambler dot ru | Date: | Fri, 10 Dec 2010 10:37:18 +0000 |
| Subject: | note 101330 added to simplexmlelement.children | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174767@lists.php.net to get a copy of this message | ||
This is my recursive simple function to parse XML with attributes.
<?php
function ParseXML($node, &$parent=array(), $only_child=true) {
//Current node name
$node_name = $node->getName();
//Let's count children
$only_child = true;
if($node->count() > 1 ) $only_child = false;
//If there is no child, then there may be text data
if($only_child){
$content="$node";
if (strlen($content)>0) $parent['content']=$content;
}
//Get attributes of current node
foreach ($node->attributes() as $k=>$v) {
$parent['@attributes'][$k]="$v";
}
//Get children
$count = 0;
foreach ($node->children() as $child_name=>$child_node) {
if(!$only_child) //If there are siblings then we'll add node to the end of the
array
LGServerPVR::ParseXML($child_node, $parent[$node_name][$child_name][$count],
$only_child);
else
LGServerPVR::ParseXML($child_node, $parent[$node_name][$child_name], $only_child);
$count++;
}
return $parent;
//(c) c01d[s]h!nE 10.12.2010
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.119.79.178
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.children.php
Edit -- https://master.php.net/note/edit/101330
Del: integrated -- https://master.php.net/note/delete/101330/integrated
Del: useless -- https://master.php.net/note/delete/101330/useless
Del: bad code -- https://master.php.net/note/delete/101330/bad+code
Del: spam -- https://master.php.net/note/delete/101330/spam
Del: non-english -- https://master.php.net/note/delete/101330/non-english
Del: in docs -- https://master.php.net/note/delete/101330/in+docs
Del: other reasons-- https://master.php.net/note/delete/101330
Reject -- https://master.php.net/note/reject/101330
Search -- https://master.php.net/manage/user-notes.php