我有兩個模式A和B與循環依賴(這是一箇中間步驟)。我用作輸入的XML文件根據xmllint和Visual Studio根據模式進行驗證。 Eclipse告訴我這兩個模式包含兩個具有相同名稱的全局組件。爲什麼我的JAXB Unmarshaller找不到在導入的模式中聲明的元素?
A.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
targetNamespace="http://foo.org/A"
xmlns="http://foo.org/A"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<xs:import schemaLocation="b.xsd" />
B.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
xmlns:foo="http://foo.org/A"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://foo.org/A" schemaLocation="a.xsd" />
我傳遞給Unmarshaller的XSD的是A.xsd。當遇到B.xsd中定義的元素時,它會投訴:
org.xml.sax.SAXParseException:cvc-elt.1:找不到元素'foo'的聲明。
我設置通過(僞)模式:
InputStream in = .. A.xsd
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
return factory.newSchema(new StreamSource(in);
任何人都可以解釋我做錯了嗎?謝謝。
查看編輯答案 – skaffman 2010-02-12 14:51:33