2

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

Rob Bowman
  • 7,632
  • 22
  • 93
  • 200

2 Answers2

4

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.)

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • So by adding the ns0 prefix, I was effectively – Rob Bowman Mar 13 '17 at 13:12
  • Many thanks for your answer Michael. To clarify my understanding, by adding the ns0 prefix, I was effectively removing the default namespace from the XSD. With the namespace set using xmlns="http://etc." then this meant that the "AdapterItemEntityNames" element of the "SchemaAttribute" complex type was in the the default namespace but the complex type "ArrayOfString" was not? If so, then this suggest elements of types are included in default namespaces but types themselves are not? – Rob Bowman Mar 13 '17 at 13:22
  • I think I get it now! 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. – Rob Bowman Mar 13 '17 at 13:51
0

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

Rob Bowman
  • 7,632
  • 22
  • 93
  • 200