Hi Some help would be appreciated wrt eliminating the hardcoded schema location from a schema which derives its types from base schema types.
If the base schema location is not hardcoded in the derived schema the following XmlSchemaException occurs (even though the base Schema has been successfully added to the schema cache) ... An unhandled exception of type 'System.Xml.Schema.XmlSchemaException' occurred in system.xml.dll Additional information: System error. Unhandled Exception: System.Xml.Schema.XmlSchemaException: Undefined complexType 'urn:schemas-x-com:base:BaseComplexType' is used as a base for complex type extension". An error occurred at file:///C:/Temp/ExtensionSchema.xsd, (7, 5). Please note that I am posting to this forum as it's my understanding that schema resolution is the responsability of the implementing parser (.Net) and not an XSD specification issue. The schemas and instance document are reproduced below... ************** BaseSchema.xsd ************** <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="BaseSchema" targetNamespace="urn:schemas-x-com:base" elementFormDefault="qualified" xmlns="urn:schemas-x-com:base" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="BaseComplexType"> <xs:sequence /> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> <xs:element name="Base" type="BaseComplexType"></xs:element> <xs:element name="BaseContainer"> <xs:complexType> <xs:sequence> <xs:element ref="Base" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> ******************* ExtensionSchema.xsd ******************* <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="ExtensionSchema" targetNamespace="urn:schemas-y-com:extension" elementFormDefault="qualified" xmlns="urn:schemas-y-com:extension" xmlns:base="urn:schemas-x-com:base" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- <xs:import namespace="urn:schemas-x-com:base" schemaLocation="file:///C:/Temp/BaseSchema.xsd" /> --> <xs:complexType name="DerivedComplexType"> <xs:complexContent mixed="true"> <xs:extension base="base:BaseComplexType"> <xs:sequence> <xs:element ref="DerivedEntity" /> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="DerivedEntity" type="xs:string"></xs:element> </xs:schema> *************** DerivedTest.xml *************** <?xml version="1.0" encoding="utf-8" ?> <BaseContainer xmlns="urn:schemas-x-com:base" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:e="urn:schemas-y-com:extension"> <Base name="arg4" xsi:type="e:DerivedComplexType"><e:DerivedEntity>Derived</e:DerivedEntity></ Base> </BaseContainer> ***************************** C# validation code snippet... ***************************** string testFln = "C:\\Temp\\DerivedTest.xml"; XmlTextReader txtRdr = new XmlTextReader(testFln); XmlSchemaCollection xsc = new XmlSchemaCollection(); string baseSchemaURI = "file:///C:/Temp/BaseSchema.xsd"; xsc.Add("urn:schemas-x-com:base", baseSchemaURI); string derSchemaURI = "file:///C:/Temp/ExtensionSchema.xsd"; //throws the XmlSchemaException if the xs:import is commented out in the derived schema xsc.Add("urn:schemas-y-com:extension", derSchemaURI); XmlValidatingReader valRdr = new XmlValidatingReader(txtRdr); valRdr.ValidationType = ValidationType.Schema; valRdr.Schemas.Add(xsc); valRdr.ValidationEventHandler += new ValidationEventHandler(IDefValidationEventHandler); while (valRdr.Read()) { } valRdr.Close();