Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7458 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50458 invoked by uid 1010); 1 Feb 2004 15:03:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 50410 invoked from network); 1 Feb 2004 15:03:17 -0000 Received: from unknown (HELO shiva.mind.de) (212.42.230.204) by pb1.pair.com with SMTP; 1 Feb 2004 15:03:17 -0000 Received: from [192.168.1.100] (p508EA999.dip.t-dialin.net [80.142.169.153]) by shiva.mind.de (Postfix) with ESMTP id C2A1597B96; Sun, 1 Feb 2004 16:03:14 +0100 (CET) Date: Sun, 1 Feb 2004 16:01:28 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <169-733797859.20040201160128@marcus-boerger.de> To: Derick Rethans Cc: PHP Developers Mailing List In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] SimpleXML->children() and text nodes From: helly@php.net (Marcus Boerger) Hello Derick, Sunday, February 1, 2004, 12:47:17 AM, you wrote: > Hello, > I was wondering on how to iterate over the elements of in > the following piece of XML: > > > foo > bar > foobar > > > when I iterate over $s->body->children() I only get the and > the . 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). > 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:helly@php.net