I have several small xsd files I stripped out of others due to repetition. I thought that I could reduce maintenance if a type changed. So here is a one example:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="StartCodeType">
<xs:restriction base="xs:integer">
<xs:pattern value="99[0-9]{3,6}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Now I have a xsd that is trying to include this file like so:
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.quikq.com/xsd/unlukupRequest"
xmlns="http://www.quikq.com/xsd/unlukupRequest"
elementFormDefault="qualified" >
<xs:include schemaLocation="TrimmedStringType.xsd" />
<xs:include schemaLocation="StartCodeType.xsd" />
<xs:include schemaLocation="AscendDescendFlag.xsd" />
(etc)
My program uses Xerces SAX2 to parse the XML. Here's the error I get:
Error at file "/home/dfcuser/unlukupRequest.xsd", line=32, column=69, XML element=, Type not found in http://www.quikq.com/xsd/unlukupRequest:StartCodeType
Error at file "/home/dfcuser/unlukupRequest.xsd", line=34, column=87, XML element=, Type not found in http://www.quikq.com/xsd/unlukupRequest:TrimmedStringType
Error at file "/home/dfcuser/unlukupRequest.xsd", line=38, column=68, XML element=, Base type could not be found: TrimmedStringType
Error at file "/home/dfcuser/unlukupRequest.xsd", line=50, column=108, XML element=, SimpleType (http://www.quikq.com/xsd/unlukupRequest:AscendDescendFlag) for attribute: ad_flag not found
Anyway I figured this would work since my 'types' don't have a namespace defined.
Here's the XSD
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.quikq.com/xsd/unlukupRequest"
xmlns="http://www.quikq.com/xsd/unlukupRequest"
elementFormDefault="qualified" >
<!--
Homebrewed data types for more strict checking on different fields
-->
<xs:include schemaLocation="StartCodeType.xsd" />
<xs:include schemaLocation="TrimmedStringType.xsd" />
<xs:include schemaLocation="AscendDescendFlag.xsd" />
<!--
Describes the root element
-->
<xs:element name="unlukupRequest">
<xs:complexType>
<xs:sequence>
<xs:element ref="transaction" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!--
Describes the response element, which is the child to the authNotifyResponse root
-->
<xs:element name="transaction">
<xs:complexType>
<xs:sequence>
<xs:element name="startCode" type="StartCodeType" />
<xs:element name="ununit" type="xs:string" minOccurs="0" />
<xs:element name="exception" type="TrimmedStringType" minOccurs="0" />
<xs:element name="opt" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="TrimmedStringType">
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
开发者_Python百科 <xs:element name="orderBy" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="field" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
<xs:attribute name="ad_flag" type="AscendDescendFlag" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rangeLower" type="xs:integer" minOccurs="0" />
<xs:element name="rangeUpper" type="xs:integer" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The XSD driver file as you present it appears to be legal; when I save it and your StartCodeType.xsd file locally, they behave as expected. My guess is that for reasons I cannot guess Xerces is not finding the included files.
If you inject syntax or other errors into the included schema documents does Xerces complain about them? (If not, maybe it's not reading them; that would explain why it can't find the type definitions.)
If you supply the target namespace explicitly in the included schema documents, instead of relying on chameleon include, does that change the behavior?
精彩评论