While I think this would make SimpleXML more stupid, not less, as it seems braindead to me to allow users to create documents ambiguously and/or which essentially violate the XML namespace spec, I think the way to do this would be to define a magic constant and use that. E.g.

const SIMPLEXML_DEFAULT_UNPREFIXED = 0

I used 'default unprefixed' to better describe what is going to happen in terms of namespaces (as within the context of a namespaced document is the only time this would be needed): the element is going to be created in the default namespace by virtue of being unprefixed. This highlights to the user the ambiguity involved (it is not necessarily known what the default namespace is at any point), as well as the 'priority' the XML generation will take at that point (of adding an unprefixed element).

-1 for using "unqualified"; whatever is used should not be a possibly valid namspace name.

Ben.



On 29/04/11 7:48 AM, Tom Samplonius wrote:


That patch is not a good idea.

Assume you have this situation:

<foo xmlns="urn:lol">
<x:bar xmlns:x="urn:hai">
</x:bar>
</foo>

Adding a child "baz" to bar and have it default to no namespace

Actually, my patch wouldn't change the default action of addChild(). It would 
still inherit the namespace qualification of the parent by default.

prefix would result in this:

<foo xmlns="urn:lol">
<x:bar xmlns:x="urn:hai">
<baz />
</x:bar>
</foo>

Now<baz />  would be in the namespace "urn:lol".

I don't see why this is a problem? I actually need to be able to add 
unqualified child elements.

Keep in mind that xmlns="" is, as per the XML spec, a perfectly valid
way to reset the namespace of an element.

Right now, the behavior of addChild() is:

* $namespace is unspecified -->  inherit from parent
* $namespace is specified -->  use that as the namespace for the element (and this could 
be "")

I need a third option, where I can add an element that is unqualified. There really are just two 
possible choices, either add a new "value" of $namespace (like (int) 0) that requests 
this behavior. Or, use some sort of magic namespace value (like "unqualified") to specify 
an unqualified element.

Is there any opinion on which is better for addChild()?

...
SimpleXML is supposed to be simple (I find it more stupid than simple, but 
that's my personal opinion).
I guess that's why it, by default, inherits the parent namespace

The only way to make it less stupid, is to start fixing it.


Tom


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

Reply via email to