a) Why must global element and attribute declarations always belong to a namespace and as such must always be qualified within instance documents?
b) Are local element/attribute declarations ( with their form
attributes set to unqualified
) still part of a schema’s target namespace, even though they aren’t associated with any namespace in instance documents?
c) Even if type/group declaration is global, it is still part of the target namespace and thus when referring to global declarations we must include the target namespace prefix.
Anyways, is there a particular reason why global declarations are part of a target namespace while local declarations aren’t? Namely, even if global type/group declarations wouldn’t belong to a target namespace, we could still refer to them within our Xml Schema, so there must be other benefits for them to be part of a namespace?!
Thank you
EDIT:
@user437291: If you understand the concept of the namespaces and qualified name why you use words "local" and "global" which is not a part of the concept?
But why do local type declarations need to be members of Xml Schema’s target namespace? They are not referenced from instance documents or other Xml Schemas, so what is the purpose/benefit of them being a member of a target namespace?
Moreover the question whether an element or an attribute belong to a namespace is really independent from the its "qualification". It is different properties like color and size of something.
How can an element/attribute belong to a namespace and at the same time doesn’t have to be qualified in instance documents? In programming languages if type T
is a member of a namespace N1
, it means that its fully qualified name is N1.T
and thus other types need to refer to this type using fully qualified name N1.T
( here I’m ignoring the using
directives etc ).
I would expect it’s the same with Xml Schemas and xml instance documents - thus, as I understand it, when Xml Schema validator parsing Contacts.xml
encounters qualified element contact:firstName
, it searches Contacts.xsd
for a matching element declaration using a name http://www.someDomain.com.firstName.
After it finds a match, validator then proceeds with the next element in Contacts.xml
, which is lastName
. Seeing that lastName
element is unqualified
, it searches Contacts.xsd
for an element declaration named lastName
. Now if within Contacts.xsd
its fully qualified name was http://www.someDomain.com.lastName
, then validator wouldn’t be able to find the matching declaration! But it does find a matching declaration, so I’m assuming lastName
isn't a member of namespace http://www.someDomain.com
Contacts.xml
<?xml version="1.0" encoding="UTF-8"?>
<contact:contact
xmlns:contact="http://www.someDomain.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://www.someDomain.com contacts1.xsd">
<contact:firstName></contact:firstName>
<lastName></lastName>
</contact:contact>
Contacts.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.someDomain.com" targetNamespace="http://www.someDomain.com" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" />
<xs:element name="lastName" form="unqualified"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>