XSD导入问题

时间:2012-08-27 09:52:49

标签: java xml-parsing jaxb xsd

我有三个XSD:deviceprofile.xsd,relatedType.xsd和profilelist.xsd

deviceprofile.xsd是引用relatedtype.xsd的根XSD,后者又指profilelist.xsd。

relatedtype.xsd和profilelist.xsd之间的引用工作正常,但deviceprofile.xsd和relatedType.xsd之间的关系给出了问题。

我已经使用相关的命名空间导入了XSD,但在使用JAXB解析deviceprofile.xsd时,它给出了:

[ERROR] src-resolve: Cannot resolve the name 'relatedData' to a(n) 'element decl
aration' component.
line 47 of file:/D:/Personal/Java/Trials/src/com/asl/trials/cea/xml/deviceprof
ile.xsd

Failed to parse a schema.

XSD都在同一个目录中,所以我可以肯定它不是路径问题。

有人可以指出我做错了吗?

我已附上以下XSD的相关摘要(以防万一):

deviceprofile.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:schemas-upnp-org:remoteui:uilist-1-0" targetNamespace="urn:schemas-upnp-org:remoteui:uilist-1-0" xmlns:xs="http://www.w3.org/2001/XMLSchema"  elementFormDefault="qualified" attributeFormDefault="unqualified" id="uilist">
<xs:import namespace="urn:schemas-ce-org:ce-html-server-caps-1-0" schemaLocation="relatedtype.xsd" />
<xs:element name="uilist">
<xs:complexType>
<xs:sequence>
<xs:element ref="relatedData" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
relatedtype.xsd
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns="urn:schemas-ce-org:ce-html-server-caps-1-0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:schemas-ce-org:ce-html-server-caps-1-0"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="profilelist.xsd" />
    <xs:element name="relatedData" type="relatedType" />
    <xs:complexType name="relatedType">
        <xs:sequence>
            <xs:element name="keyword" type="xs:string" minOccurs="0"
                maxOccurs="unbounded" />
            <xs:element ref="profilelist" minOccurs="1" maxOccurs="unbounded" />
            <xs:element name="saveStateStorageURL" type="xs:anyURI"
                minOccurs="0" maxOccurs="1" />
            <xs:element name="savedStatesInfo" type="savedStatesInfoType"
                minOccurs="0" maxOccurs="1" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="savedStatesInfoType">
        <xs:attribute name="saveTime" type="xs:string" />
        <xs:attribute name="forUser" type="xs:string" use="optional" />
    </xs:complexType>
</xs:schema>
profilelist.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="profilelist" type="profileListType" />
    <xs:complexType name="profileListType">
</xs:complexType>
...
</xs:schema>

1 个答案:

答案 0 :(得分:1)

deviceprofile.xsd架构中,您需要声明urn:schemas-ce-org:ce-html-server-caps-1-0命名空间,然后在ref值中包含相应的前缀。下面我使用了foo前缀:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:schemas-upnp-org:remoteui:uilist-1-0"
    targetNamespace="urn:schemas-upnp-org:remoteui:uilist-1-0" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:foo="urn:schemas-ce-org:ce-html-server-caps-1-0"
    elementFormDefault="qualified" 
    attributeFormDefault="unqualified" id="uilist">
    <xs:import namespace="urn:schemas-ce-org:ce-html-server-caps-1-0"
        schemaLocation="relatedtype.xsd" />
    <xs:element name="uilist">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="foo:relatedData" minOccurs="1" maxOccurs="1" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>