14

現在、javax.xml.validation.SchemaFactory. 残念ながら、newSchema(Source schema)関数を呼び出すと、次のエラーが発生します。

Caused by: org.xml.sax.SAXParseException; systemId: file:/C:/Users/C42056/Documents/workspace-sts-3.2.0.RELEASE/cec-sample-ws-integration-2-war/target/classes/WEB-INF/schemas/xsd/individual/PrivateComponentTypes_4_0.xsd; lineNumber: 33; columnNumber: 88; src-resolve: Cannot resolve the name 'utility:ObjectStatusDateType' to a(n) 'type definition' component.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLocal(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseLocalElements(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at com.sei.ec.xml.validation.SimpleXmlValidator.loadSchema(SimpleXmlValidator.java:70)
at com.sei.ec.xml.validation.SimpleXmlValidator.<init>(SimpleXmlValidator.java:83)
... 75 more

このutility:ObjectStatusDateType要素は、関数に渡す .xsd ファイルで使用されnewSchema(Source schema)ます。ObjectStatusDateType別の .xsd ファイルからインポートしています。ファイル パスを 3 回チェックしました。名前utility空間も適切に宣言されています。

関数に渡すスキーマのスニペットを次に示します (LocateCoverageIndexesByIdentifier_3_0.xsd):

<xs:import namespace="http://www.sei.com/utility/1/" schemaLocation="../../utility/InvocationOutcome_1_0.xsd"/>
<xs:import namespace="http://www.sei.com/utility/1/" schemaLocation="../../utility/ObjectHistory_1_0.xsd"/>
<xs:import namespace="http://www.sei.com/individual/component/4/" schemaLocation="../PrivateComponentTypes_4_0.xsd"/>
<xs:import namespace="http://www.sei.com/individual/shared/5/" schemaLocation="../IndividualTypes_5_0.xsd"/>
.
. <!-- Some more stuff -->
.
<xs:element name="coveragePeriod" 
            type="utility:ObjectStatusDateType" 
            minOccurs="0"/>

これは ObjectHistory_1_0.xsd からのものです。

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:tns="http://www.sei.com/utility/1/" 
           targetNamespace="http://www.sei.com/utility/1/" 
           elementFormDefault="qualified" 
           attributeFormDefault="unqualified" 
           version="1.0">
.
. <!-- Some more stuff -->
.
  <xs:complexType name="ObjectStatusDateType">
    <xs:sequence>
      <xs:element name="effectiveDate" type="xs:date"/>
      <xs:element name="cancelDate" type="xs:date" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

そして最後は豆

<bean id="locateClaimValidator" 
      class="com.sei.ec.xml.validation.SimpleXmlValidator">
  <constructor-arg>
    <value>classpath:WEB-INF/schemas/xsd/individual/ci/LocateCoverageIndexesByIdentifier_3_0.xsd
    </value>
  </constructor-arg>
</bean>

以前にこの種の問題に遭遇した人はいますか?

4

4 に答える 4

12

私は以前にこの問題を抱えていました。すべてが Eclipse で検証されましたが、実行中に壊れました。複数のスキーマを同じ名前空間にインポートするスキーマはありますか?

このようなものは機能しませんが、Eclipse によって検証されます。

<import namespace="http://www.whatever.gov" location="../wherever" />
<import namespace="http://www.whatever.gov" location="../folder/superawesomeschema.xsd" />
于 2013-09-18T16:59:09.143 に答える
5

Xerces を使用すると、この機能 http://apache.org/xml/features/honour-all-schemaLocationsを true に設定することで解決できます。

この機能http://apache.org/xml/features/honour-all-schemaLocationsは、Xerces 2.7.0 以降でのみ使用できます。Java 5.0 および 6.0 の現在のリリースには、Xerces 2.6.2 が組み込まれています。したがって、これを機能させるには、より新しい Xerces ライブラリを使用する必要があります。行を含むファイルへのコピーxml-apis.jarとファイルの作成xercesImpl.jar<jdk-home>/jre/lib/endorsedjaxp.properties<jdk-home>/jre

javax.xml.validation.SchemaFactory\:http\://www.w3.org/2001/XMLSchema=org.apache.xerces.jaxp.validation.XMLSchemaFactory
于 2013-11-29T10:05:49.880 に答える
4

Maven プラグイン jaxb2-maven-plugin を実行するときに同じ問題が発生しました。解析するxsdファイルを明示的に言及した後、それは魅力的に機能しました:

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>jaxb2-maven-plugin</artifactId>
 <version>1.6</version>
    <executions>
     <execution>
      <id>xjc</id>
      <goals>
       <goal>xjc</goal>
      </goals>
     </execution>
    </executions>
    <configuration>
     <schemaFiles>MySchema.xsd</schemaFiles>
     <outputDirectory>src/main/java</outputDirectory>
    </configuration>
</plugin> 
于 2014-06-25T10:21:53.563 に答える