1

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

deviceprofile.xsd 是指relatedtype.xsd 的根XSD,而relatedtype.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>
4

1 回答 1

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>
于 2012-08-27T13:49:06.783 回答