note 99342 added to simplexmlelement.children
| From: | alan at performantsystems dot com | Date: | Wed, 11 Aug 2010 21:40:29 +0000 |
| Subject: | note 99342 added to simplexmlelement.children | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171587@lists.php.net to get a copy of this message | ||
As I have occasion to retrieve a single data item rather than a list, I wanted a way to just grab
and parse one data item from XML. Here is one way to do that:
<?php
echo "\n";
$XML =
'<data>
<USERS>
<ID>alang</ID>
<NAME>Alan Gruskoff</NAME>
<ROLE>mgr</ROLE>
</USERS>
</data>';
$xmlObject = new SimpleXMLElement($XML);
$node = $xmlObject->children();
echo "var_dump node\n";
var_dump($node);
echo "\n";
echo "\nnode ID=". $node[0]->ID;
echo "\nnode NAME=". $node[0]->NAME;
echo "\nnode ROLE=". $node[0]->ROLE;
echo "\n";
?>
This will show the contents of the $node child of the $xmlObject and then the specific element
values.
----
Server IP: 69.147.83.197
Probable Submitter: 75.27.235.151
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.children.php
Edit -- https://master.php.net/note/edit/99342
Del: integrated -- https://master.php.net/note/delete/99342/integrated
Del: useless -- https://master.php.net/note/delete/99342/useless
Del: bad code -- https://master.php.net/note/delete/99342/bad+code
Del: spam -- https://master.php.net/note/delete/99342/spam
Del: non-english -- https://master.php.net/note/delete/99342/non-english
Del: in docs -- https://master.php.net/note/delete/99342/in+docs
Del: other reasons-- https://master.php.net/note/delete/99342
Reject -- https://master.php.net/note/reject/99342
Search -- https://master.php.net/manage/user-notes.php