Closed vog closed 7 years ago
Just a quick addition to my statements above: These are only true for schemas where an explicit targetNamespace
is set.
For schemas without namespaces, and most importantly for Chameleon Includes (see https://www.w3.org/TR/xmlschema11-1/#src-include), an absent namespace in a QName is indeed resolved to the (effective) targetNamespace. These two special cases are handled as well in pull request #81.
Still, the resolution of those QNames is completely independent from the namespace to which the definition name
s (as local names) are bound.
Pull request #69 did not fix #67 in the correct way. The solution was too superficial. The real problem is deeper in the xsd2json code and needs to be fixed with a more thorough change.
The main problem is that the
name
of a definition is treated as aQName
in xsd2json. But it is really just a local name that is always bound to the target namespace. This subtle difference is important, because all the realQName
s (type
,ref
, etc.) do not care about the target namespace at all. If these have no prefix, they must be bound to whatever namespace is bound to the empty prefix (xmlns=...
). Even more so, there is a special rule in XML Schema that if the empty prefix is unbound, it defaults to the XML Schema namespace, not the target namespace!So it is wrong to ever bind targetNS to the empty prefix by any automatism. Instead, definition names need to be resolved by a separate mechanism.
To illustrate the issue, consider the following definition:
Here,
Foo
is bound to thehttp://example.com/foo
namespace, whiledate
is looked up in thehttp://example.com/bar
namespace.Moreverover, if the
xmlns=...
definition is left out:then
Foo
is still bound to thehttp://example.com/foo
namespace, whiledate
is looked up in thehttp://www.w3.org/2001/XMLSchema
namespace.In neither case
date
is ever looked up in the target namespace.