Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7048 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62706 invoked by uid 1010); 13 Jan 2004 14:21:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 62641 invoked from network); 13 Jan 2004 14:21:49 -0000 Received: from unknown (HELO xaxa.search.ch) (195.141.85.117) by pb1.pair.com with SMTP; 13 Jan 2004 14:21:49 -0000 Received: from localhost (localhost [127.0.0.1]) by xaxa.search.ch (Postfix) with ESMTP id C2AC96D85D; Tue, 13 Jan 2004 15:21:48 +0100 (CET) Received: by xaxa.search.ch (Postfix, from userid 65534) id BE7D26D860; Tue, 13 Jan 2004 15:21:47 +0100 (CET) Received: from cschneid.com (ultrafilter-i [192.168.85.2]) by xaxa.search.ch (Postfix) with ESMTP id D928A6D85D; Tue, 13 Jan 2004 15:21:46 +0100 (CET) Message-ID: <4003FEFA.2090700@cschneid.com> Date: Tue, 13 Jan 2004 15:21:46 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031009 X-Accept-Language: de-ch, en-us, en MIME-Version: 1.0 To: Rob Richards Cc: Adam Maccabee Trachtenberg , internals@lists.php.net References: <00fe01c3d9d1$6e8618a0$f7dea8c0@cyberware.local> In-Reply-To: <00fe01c3d9d1$6e8618a0$f7dea8c0@cyberware.local> X-Enigmail-Version: 0.76.7.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Checker-Version: SpamAssassin 2.61 (1.212.2.1-2003-12-09-exp) on xaxa.search.ch X-Spam-Level: X-Spam-Status: No, hits=0.0 required=5.0 tests=none autolearn=ham version=2.61 X-Virus-Scanned: by AMaViS 0.3.12pre8 Subject: Re: [PHP-DEV] SimpleXML: Moving Forward From: cschneid@cschneid.com (Christian Schneider) Rob Richards wrote: > From: Adam Maccabee Trachtenberg > >> accessing the text node children of an element is akin to object >> properties ($foo->bar); the syntax of accessing attributes is akin >> to array elements ($foo['bar']). Hmm... This is somewhat up-side-down language wise. Attributes are properties of a node and the node contains children like an array contains elements. But I guess we'll keep it that way for nesting sake ($foo->foo2->foo3 is so much nicer than $foo['foo2']['foo3']). But let's take a look on how I'd use it (xml formatted for readability): $foo = simplexml_load_string(' ab foo2a cd foo2b ef foo3 foo4 foo3 gh '); foreach ($foo as $node) => foo2a foo2b foo3 foreach ($foo->foo2 as $node) => foo2a foo2b foreach ($foo->foo3 as $node) => foo4 foreach ((array)$foo->foo3 as $node) => foo4 foreach ($foo->foo3->foo4 as $node) => nothing foreach ((array)$foo->foo3->foo4 as $node) => foo4 What seems wrong here is that to output nodes where there can be 0 to multiple instances I have to do something like: if ($foo->$nodename) { if (is_array($foo->$nodename)) { foreach ($foo->$nodename as $node) echo "$node\n"; } else echo "{$foo->$nodename}\n"; } else echo "No node $nodename found\n"; $nodename = 'node1' => No node node1 found $nodename = 'node2' => foo2a foo2b $nodename = 'node3' => foo3 > Attributes are handled associative arrays, so given an element with 2 > attributes with the same name, but in different namespaces, it wont work: > Right now foo['bar'] will be an array('x', 'y') in that case. We're losing the namespaces here but get the values. Simple or broken? Not sure. > Should only be direct descendants. One should be able to navigate the entire > tree (elements/attributes) in a standard way without having to use xpath. I agree. What about getChildren($level = 1) with $level=0 meaning all? This offers both functionalities while having a default we decide on. As right now there is no easy (read non-xpath/xquery) way of getting the attributes hidden in the magic array of $foo I think getAttributes should be added too. No other functions though. Should these be methods? I think so. > $foo = simplexml_load_string('abtestcd'); > $ns = $foo->xsearch('child::text()'); > foreach ($ns as $node) > print "Node Value: ".$node."\n"; I would actually expect abcd but only once: Node Value: abcd Concatenating all text parts _and_ returning them once for each part definitely seems wrong. +1 on getChildren/getAttributes (function or method) -1 on more functions I think it's quite usable this way and simple enough to use to earn the name SimpleXML. - Chris