Adam Maccabee Trachtenberg wrote:
> 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 <foo ns="a">. It's different from <foo>, 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:
> 
> <foo ns:a="x">
>   <a:bar/>
>   <a:bar ns:a="y"/>
> </foo>
> 
> These two <a:bar>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.

Yeah, I agree actually.  My real beef is that simplexml and var_dump()
don't place nicely with each other.  var_dump() ends up lumping the
namespaced elements in with the non-namespaced elements of the same
name, but when you iterate through things manually they are not lumped
together and the only way to get at the namespaced elements is by
checking for them directly with the appropriate children() call.

I am fine with having to manually dereference the namespace and keeping
things completely separate.  I'd just like it to be easier for people to
use var_dump() on a simplexml object and not have it confuse the heck
out of them by showing them arrays with 2 elements in them which when
they iterate only get 1 or if they call count() on it only get 1.

-Rasmus

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to