[xsd-users] How to determine if the xsd:QName is qualified?
Boris Kolpackov
boris at codesynthesis.com
Tue Jun 8 06:23:57 EDT 2010
Hi Vladimir,
In the future please keep your replies CC'ed to the xsd-users mailing
list as discussed in the posting guidelines:
http://www.codesynthesis.com/support/posting-guidelines.xhtml
Vladimir Vasilyev <Vladimir.Vasilyev at samtec.de> writes:
> > The "NCName" value is qualified in the above XML file because you
> > have a default namespace declaration (xmlns="MyNamespace") which
> > makes all names without an explicit namespace prefix end up in
> > this namespace.
>
> So it is completely the problem of XML, right? It has nothing to do with
> Code Synthesis XSD, does it?
This is not a problem per se. It is just how the QName built-in type
works per the XML Schema specification:
"QName represents XML qualified names. The ·value space· of QName is the
set of tuples {namespace name, local part}, where namespace name is an
anyURI and local part is an NCName. The ·lexical space· of QName is the
set of strings that ·match· the QName production of [Namespaces in XML].
Note: The mapping between literals in the ·lexical space· and values in
the ·value space· of QName requires a namespace declaration to be in scope
for the context in which QName is used."
http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#QName
In other words, to resolve the lexical space representation of QName (e.g.,
"p:foo") to its value space (e.g., {http://www.example.com,foo}), the XML
Schema processor has to perform the standard XML prefix-to-namespace
resolution.
> Could you please confirm that if i would work with XML using another API
> i would get completely the same behaviour? Or is it xerces specifics?
> (
> For example
> http://java.sun.com/j2ee/1.4/docs/api/javax/xml/namespace/QName.html
> says:
>
> QName represents a qualified name as defined in the XML specifications.
>
> The value of a QName contains a Namespace URI, local part and prefix.
>
> The prefix is included in QName to retain lexical information when
> present in an XML input source.
>
> If not specified, the Namespace URI is set to "" (the empty string). If
> not specified, the prefix is set to "" (the empty string).
> )
I am not sure which specification Java follows, but the XML Schema spec
clearly states that the value space of QName is a namespace/local name
pair and does not include the prefix. Storing prefix in QName opens a
big can of worms. For example, you may load XML that uses one prefix
for a particular namespace and then save it using a different prefix
for the same namespace. Should the prefix in QName now be disregarded
or should we insert a namespace declaration in the resulting XML
document every time such a value is serialized?
Boris
More information about the xsd-users
mailing list