problem for me, as I have an XML schema that specifies that the
child elements must not namespace qualified.

Is this possible in an XML schema? I don't know much about schemas,
but
...

Absolutely, if the XML schema has the "elementFormDefault" attribute
set to "unqualified", the child elements must be unqualified.

I'm not sure what this means. If any element name or attribute name that
is not a namespace declaration is not a qualified name, the document
does not conform to the XML namespaces specification.

From http://www.w3.org/TR/xml-names/#ns-qualnames :

"In XML documents conforming to this specification, some names
(constructs corresponding to the nonterminal Name) MUST be given as
qualified names"

And from http://www.w3.org/TR/xml-names/#ns-using :

"In XML documents conforming to this specification, element names are
given as qualified names ... Attributes are either namespace
declarations or their names are given as qualified names"

My guess would be that either:

- 'Unqualified' in this context doesn't actually mean 'unqualified
  name', but means 'not in a namespace'. In this case, to specify such
  an element in an XML document that uses namespaces, an unprefixed name
  must be used with no default namespace in scope.

- 'Unqualified' is not meant to be mixed with 'qualified' in the same
  document, and exists so that XML with elements/attribute names using
  colons can be used without a namespace-interpretation; this is not
  recommended, but legal, and parsers are required to be able parse such
  documents. If this is the case, things are beyond rescue, I think; the
  XML described by the schema does not conform to the XML namespace
  spec, and we can't expect SimpleXML to deal with it, certainly not in
  a namespace-aware way.

I would also expect, if the child were to be namespaced, that these
are equivalent:

<ns1:parent xmlns="whatever" xmlns:ns1="whatever">
<child>abc</child>
</ns1:parent>

<ns1:parent xmlns:ns1="whatever">
<ns1:child>abc</ns1:child>
</ns1:parent>
...

In the first case, the <child> element is unqualified,

No, it is not. It is syntactically a qualified name, if the document
follows the XML namespace spec. But it is an unprefixed qualified name.
In this case, though, it is in the "whatever" namespace, due to scoping
rules.

From http://www.w3.org/TR/xml-names/#defaulting :

"The scope of a default namespace declaration extends from the beginning
of the start-tag in which it appears to the end of the corresponding
end-tag,"

So the xmlns="whatever" is in effect for <child>. Furthermore:

"A default namespace declaration applies to all unprefixed element names
within its scope. ... If there is a default namespace declaration in
scope, the expanded name corresponding to an unprefixed element name has
the URI of the default namespace as its namespace name."

So the namespace name of <child> is "whatever".

and in the second, it is not.

Yes. It is both qualified and prefixed. Child very obviously is in the
"whatever" namespace.

They are not the same thing, either semantically or otherwise.

So they are semantically the same, at least in that <child> is in the
"whatever" namespace in both cases.

and the xmlns="" is necessary. If this functionality were removed,
how could this be done?

For what?  In the spec (http://www.w3.org/TR/xml-names/#iri-use), it
says:

"The empty string, though it is a legal URI reference, cannot be used
as a namespace name."

xmlns="" does not mean elements are in a namespace with an empty name,
but that there is no default namespace.

From http://www.w3.org/TR/xml-names/#defaulting :

"The attribute value in a default namespace declaration MAY be empty.
This has the same effect, within the scope of the declaration, of there
being no default namespace."

So these are equivalent:

<ns1:parent xmlns="whatever" xmlns:ns1="whatever">
<child xmlns="">abc</child>
</ns1:parent>

<ns1:parent xmlns:ns1="whatever">
<child>abc</child>
</ns1:parent>

In both cases, child is not in a namespace. Perhaps this is what is
meant by 'unqualified' in the XML schema stuff.

Sure, SimpleXML could perhaps output XML that is slightly more
efficient/less verbose than it currently does, but its output is not
incorrect, and the functionality you want to remove is necessary in
other circumstances.

I don't see how removing the ability to use "" as a namespace is an
issue, since "" can't be used as a namespace name.

It removes the ability to add a non-namespaced element at a position in
a document where a default namespace is in effect. Specifying ""
indicates a non-namespaced element should be added, and adding xmlns=""
is the way SimpleXML ensures it is achieved, by ensuring it is as if no
default namespace is in effect.

Cheers,

Ben.




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

Reply via email to