循環依存関係を持つ 2 つのスキーマ A と B があります (これは中間ステップです)。入力として使用している XML ファイルは、xmllint と Visual Studio に従ってスキーマに対して検証されます。Eclipse から、両方のスキーマに同じ名前の 2 つのグローバル コンポーネントが含まれていることがわかります。
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);
誰かが私が間違っていることを説明できますか? ありがとう。