This depends on a) What generated the instance and b) Are elements (or attributes) with the same name defined both in A.xsd and the imported schema B.xsd. If you generated the sample instance document with, say, XMLSpy, then it typically assigns namespaces to generated elements - required or not. In the second case, there is no way to use elements with the same name, originating in different schemas (vocabularies) in a none prefixed way in the same instance document.
Tom Silverman: SCJP5, SCJD6, SCWCD5, SCBCD5, IBM-142, ScrumMaster
Joined: Jan 10, 2007
Exampel : lib.xsd import book.xsd (both with unqualified)
I check the validation in XMLSpy and i get validation error due to :
File Untitled43.xml could not be validated because of an error in XML Schema/DTD (see below)
Schema at location 'c:\proffesional\jaxb\test-import\import\src\main\lib.xsd' has target namespace 'http://www.library.org' rather than ''.
Error location: Library / @xsi:noNamespaceSchemaLocation
schema_reference: Schema at location 'c:\proffesional\jaxb\test-import\import\src\main\lib.xsd' has target namespace 'http://www.library.org' rather than ''.
As far as I can see this is all normal.
When the setting in your schema 'elementFormDefault' is set to 'unqualified' your elements in the resulting XML document may :
a) NOT have a prefix (besides the root element)
b) NOT be in a default namespace (as that would make them qualified as well)
This example validates to 'unqualified':
This example validates as 'qualified':
and is equivalent to a different notation with a default namespace:
So if you do not want prefixes, use qualified and work with a default namespace.
Of course, if you use other 'components' from schema's in a different namespace, you will have to declare a namespace with prefix and these parts will be fully prefixed when used in your xml
(you could get away with overriding the default namespace though, but that is just a big NO NO)