Reputation: 8701
I have the attached main.xsd which imports the types.xsd. Open this in XmlSpy (or similar) and the main.xsd will validate just fine. However, if the namespace prefix ns0 is removed from the declaration then it will not validate - even though the prefix is not used anywhere.
Good:<xs:schema xmlns:ns0="http://schemas.asidua.com/CCP/IntegrationServices/2011-11-18/Data"
Bad:<xs:schema xmlns="http://schemas.asidua.com/CCP/IntegrationServices/2011-11-18/Data"
The validation error message:
"Cannot resolve declaration or definition 'ArrayOfString' in namespace 'http://schemas.asidua.com/CCP/IntegrationServices/2011-11-18/Data'"
Can anyone please explain why the prefix is required?
Good file:GoodMain.xsd Bad file:BadMain.xsd Imported types xsd:Types.xsd
Upvotes: 2
Views: 1660
Reputation: 163262
If the namespace prefix ns0
is not used anywhere, then you can safely remove the namespace declaration xmlns:ns0="http://schemas.asidua.com/CCP/IntegrationServices/2011-11-18/Data"
What you can't do is to replace it with a different namespace declaration, xmlns="http://schemas.asidua.com/CCP/IntegrationServices/2011-11-18/Data"
. That changes the default namespace, which changes the meaning of all unprefixed names in the schema document.
Update in response to comments: More particularly, if a default namespace D is declared in a schema, then globally declared elements, types etc (<element name="x"/>
) will be in the targetNamespace of the schema, while names that refer to elements or types (type="x"
, ref="x"
) will be in namespace D. Which will tend to give problems unless D is the same as the targetNamespace.
(By the way, it's not called an "alias". You'll be understood better if you use the right terminology.)
Upvotes: 4
Reputation: 8701
By defining "xmlns=", I was saying that any unqualified elements will belong to this default namespace. Problem was, because I didn't have a "targetNamespace=" attribute for the schema, then the namespace that the default namespace targeted did not exist.
I have now defined the XSD as follows:
<xs:schema targetNamespace="http://schemas.asidua.com/CCP/IntegrationServices/2011-11-18/Data" xmlns="http://schemas.asidua.com/CCP/IntegrationServices/2011-11-18/Data" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:q2="http://microsoft.com/wsdl/types/" elementFormDefault="unqualified" attributeFormDefault="unqualified">
Full file here:best.xsd
Upvotes: 0