SimpleXML->children() and text nodes
| From: | Derick Rethans | Date: | Sat, 31 Jan 2004 23:47:17 +0000 |
| Subject: | SimpleXML->children() and text nodes | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-7442@lists.php.net to get a copy of this message | ||
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?
regards,
Derick