note 79317 added to function.simplexml-element-children
| From: | lars dot a dot johansson at se dot atlascopco dot com | Date: | Tue, 20 Nov 2007 18:41:18 +0000 |
| Subject: | note 79317 added to function.simplexml-element-children | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132439@lists.php.net to get a copy of this message | ||
Hi,
Anyone who can tell me how to parse an xml tag that contains both text and childs. e.g.
...<sql>select * from table;<conv>default.php</conv><sql>...
The only way I could extract the text (select...) was with the following snippet
foreach($xml->children() as $k => $v ) {
$elem = count($v);
$xmla = (array) $xml[0];
if (is_string($xmla["$k"]) and $elem) {
// $xmla["$k"] is 'select * from table'
}
...}
which is not very pretty.
Convert the child xml object to an array and check if the child is a string and not an end node.
It's un ugly hack, but it does the job.
----
Server IP: 129.16.214.50
Probable Submitter: 212.75.80.254
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-children.php
Edit -- https://master.php.net/note/edit/79317
Del: integrated -- https://master.php.net/note/delete/79317/integrated
Del: useless -- https://master.php.net/note/delete/79317/useless
Del: bad code -- https://master.php.net/note/delete/79317/bad+code
Del: spam -- https://master.php.net/note/delete/79317/spam
Del: non-english -- https://master.php.net/note/delete/79317/non-english
Del: in docs -- https://master.php.net/note/delete/79317/in+docs
Del: other reasons-- https://master.php.net/note/delete/79317
Reject -- https://master.php.net/note/reject/79317
Search -- https://master.php.net/manage/user-notes.php