Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File include/import problem with XSD

Status
Not open for further replies.

drkestrel

MIS
Sep 25, 2000
439
GB
I have problem with file includes in XML schemas. The scenario is as follows. The validation of file MyFile.xsd succeeds against MXSML4.0 and Microsoft .Net. However, it fails on XML Spy!

MyFile.xsd INCLUDES the following definition
Code:
<xsd:schema targetNamespace=&quot;[URL unfurl="true"]http://www.mycompany.org/form&quot;[/URL] xmlns:APD=&quot;[URL unfurl="true"]http://www.parentcompany.com/people/AddressAndPersonalDetails&quot;[/URL] xmlns:xsd=&quot;[URL unfurl="true"]http://www.w3.org/2001/XMLSchema&quot;[/URL] xmlns=&quot;[URL unfurl="true"]www.mycompany.org/form&quot;[/URL] elementFormDefault=&quot;qualified&quot; attributeFormDefault=&quot;unqualified&quot; version=&quot;0.4&quot; id=&quot;F01&quot;>
<xsd:include schemaLocation=&quot;people/CommonSimpleTypes-v1.xsd&quot;/>
<xsd:import namespace=&quot;[URL unfurl="true"]http://www.parentcompany.com/people/AddressAndPersonalDetails&quot;[/URL] schemaLocation=&quot;govtalk/ContactTypes-v1.xsd&quot;/>
        <!-- RestrictedStringType is defined in CommonSimpleTypes-->
	<xsd:simpleType name=&quot;F01Name&quot;>
		<xsd:restriction base=&quot;RestrictedStringType&quot;>
			<xsd:minLength value=&quot;1&quot;/>
			<xsd:maxLength value=&quot;70&quot;/>
		</xsd:restriction>
	</xsd:simpleType>

CommonSimpleTypes INCLUDES the following name space definition:
Code:
<xsd:schema xmlns:xsd=&quot;[URL unfurl="true"]http://www.w3.org/2001/XMLSchema&quot;[/URL] elementFormDefault=&quot;qualified&quot; attributeFormDefault=&quot;unqualified&quot; version=&quot;1.1&quot; id=&quot;CommonSimpleTypes&quot;>

ContactTypes INCLUDES the follow definition
Code:
<xsd:schema targetNamespace=&quot;[URL unfurl="true"]http://www.parentcompany.com/people/AddressAndPersonalDetails&quot;[/URL] xmlns:xsd=&quot;[URL unfurl="true"]http://www.w3.org/2001/XMLSchema&quot;[/URL] xmlns=&quot;[URL unfurl="true"]http://www.parentcompany.com/people/AddressAndPersonalDetails&quot;[/URL] elementFormDefault=&quot;qualified&quot; attributeFormDefault=&quot;unqualified&quot; version=&quot;1.0&quot; id=&quot;ContactTypes&quot;>
<xsd:include schemaLocation=&quot;CommonSimpleTypes-
v1.xsd&quot;/>
	<xsd:complexType name=&quot;TelephoneStructure&quot;>
		<xsd:sequence>
			<xsd:element name=&quot;TelNationalNumber&quot; type=&quot;TelephoneNumberType&quot;/>
			<xsd:element name=&quot;TelExtensionNumber&quot; type=&quot;TelephoneExtensionType&quot; minOccurs=&quot;0&quot;/>
			<xsd:element name=&quot;TelCountryCode&quot; type=&quot;TelCountryCodeType&quot; minOccurs=&quot;0&quot;/>
		</xsd:sequence>
		<xsd:attribute name=&quot;TelUse&quot; type=&quot;WorkHomeType&quot;/>
	</xsd:complexType>

However, when validating in the text view in XML Spy, I get validation error The file is not valid: Schema error- undefined value for 'type' encounteredagainst the line
Code:
<xsd:element name=&quot;TelNationalNumber&quot; type=&quot;TelephoneNumberType&quot;/>
in ContactTypes. However, validating ContactTypes alone works fine.

If I open MyFile.xsd in the Schema Design view and select validate, I get error The file is not valid:No Type with Name &quot;TelephoneNumberType&quot; has been defined in this or included/imported schemas in the ContactTypes Schema!

I think it MIGHT have something to do with the import/include for CommonSimpleTypes. However, if I take out the include for CommonSimpleTypes in MyFile.xsd, I get error when trying to use &quot;RestrictedSimpleType&quot;.

What is wrong?
 
I ran into a similar problem myself.
It's an enormous headacke as far as I consider it, when you use several namespaces across multiple schema modules.

I don't have a complete answer to your problem, because I was able to restrict the number of namespaces that I used, using a &quot;Chameleon design'. I was lucky I could do that.

In that particular design techique, you define and set a default namespace (with no prefix) in the top-most schema and the namespace will be expanded to all the included schemas.

What happens in your case is that the XMLSpy parser will append the namespace prefix you specified for the included schemas to the type name and simply does not find the type definition (the one with the namespace prefix) in the included file.

I really don't know if that's a correct behavior or not. I have to look some more into it for my own sake also...

Try to use a default namespace, if possible, unfortunately I cannot suggest you anything better.
[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top