Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:18221 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75190 invoked by uid 1010); 19 Aug 2005 07:57:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75175 invoked from network); 19 Aug 2005 07:57:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Aug 2005 07:57:20 -0000 X-Host-Fingerprint: 65.124.18.202 miranda.org Linux 2.4/2.6 Received: from ([65.124.18.202:40750] helo=miranda.org) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 21/CE-33075-FD095034 for ; Fri, 19 Aug 2005 03:57:19 -0400 Received: (qmail 2552 invoked by uid 546); 19 Aug 2005 03:57:16 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 19 Aug 2005 03:57:16 -0400 Date: Fri, 19 Aug 2005 03:57:16 -0400 (EDT) X-X-Sender: adam@miranda.org To: Rasmus Lerdorf cc: internals@lists.php.net In-Reply-To: <43054765.3000208@lerdorf.com> Message-ID: References: <43054765.3000208@lerdorf.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] Simplexml and xml namespaces From: adam@trachtenberg.com (Adam Maccabee Trachtenberg) On Thu, 18 Aug 2005, Rasmus Lerdorf wrote: > But how does this really help? I don't see how it is possible to > distinguish the namespaced title vs. the non-namespaced ones. My > suggestion here would be that for namespaced nodes the namespace alias > (or perhaps the actual namespace?) becomes the key in the nodes array. XML Namespaces are a real PITA. I remember Rob, Sterling, and I went through a variety of iterations around this. The biggest problems is that prefixes are really not something you can rely on at all -- they are just a handy fiction -- the namespace name is really what the XML processor uses. If you're consuming a feed and the provider alters the namespace prefix, but binds it to the same namespace, then the document is considered identical. However, if you're relying on a specific prefix in your code (instead of the actual namespace), then your code is busted. Since people don't always have control over producing the XML documents process, it doesn't seem reasonable to force people not to let others change prefixes. Second, default namespaces also screw things up entirely, as you have no way to access . It's different from , so they shouldn't be lumped together, but there's no prefix you can use to access it. Now you have to have a way of registering prefixes, so you can access elements in default namespaces. FWIW, this exact problem is the #1 XSLT FAQ because people don't realize that elements in a default namespace aren't the same as non-namespaced elements. (Of course there is the issue of what happens when something switches from having a prefix to being in a default namespace -- again it is the identical document, but code is broken.) Last, you can get weird rebinding of namespace prefixes: These two s are different. Ultimately, for those reasons, if you want to reliably access a XML document using namespaces prefixes, you really need to register your own prefixes for every namespace used in the document and use those in your code, or things could potentially break even under a valid XML document. It was really those two issues that caused we (I think it was largely Rob) to suggest we end up using children() and attributes() with the namespace name instead of the prefix. I really do think it is the cleanest solution that doesn't break down when you reach the edge cases. -adam -- adam@trachtenberg.com | http://www.trachtenberg.com author of o'reilly's "upgrading to php 5" and "php cookbook" avoid the holiday rush, buy your copies today!