note 79317 deleted from function.simplexml-element-children by danbrown

From: Date: Wed, 16 Sep 2009 15:34:05 +0000
Subject: note 79317 deleted from function.simplexml-element-children by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160635@lists.php.net to get a copy of this message
Note Submitter: lars dot a dot johansson at se dot atlascopco dot com ---- 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.

« previous php.notes (#160635) next »