Hello Derick,
Sunday, February 1, 2004, 12:47:17 AM, you wrote:
> Hello,
> I was wondering on how to iterate over the elements of <body> in
> the following piece of XML:
> <sx>
> <body>
> <element>foo</element>
> bar
> <baz>foobar</baz>
> </body>
> </sx>
> when I iterate over $s->body->children() I only get the <element/> and
> the <baz/>. Shouldn't it also show the text nodes?
> Another thing that would be useful to have is a tag() method, so that
> this would work too: (ie, I can check what tag I got during iteration).
> <?php
> foreach ($sx->body->children() as $node) {
> if ($node->tag() == 'element') {
> /* do this */
> }
> }
?>>
> or can I do that in a different way now?
Have a go with classes SimpleXMLIterator and RecursiveIteratorIterator
from SPL:
foreach(new RecursiveIteratorIterator(new SimpleXMLIterator($xml_string)) as
$node) {
/* do whatever */
}
--
Best regards,
Marcus mailto:[EMAIL PROTECTED]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php