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.

-adam

-- 
[EMAIL PROTECTED] | http://www.trachtenberg.com
author of o'reilly's "upgrading to php 5" and "php cookbook"
avoid the holiday rush, buy your copies today!

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

Reply via email to