[英]src-resolve: Cannot resolve the name 'ST' to a(n) 'type definition' component in HL7
[英]SAXParseException; src-resolve: Cannot resolve the name '…' to a(n) 'type definition' component
我正在嘗試進行模式驗證,目前使用的是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)
函數。 我從另一個.xsd文件導入ObjectStatusDateType
我已經檢查了文件路徑。 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>
以前有人遇到過這類問題嗎?
我以前遇到過這個問題。 所有在Eclipse中驗證的東西,但在運行時破壞了。 您的任何模式是否將多個模式導入同一名稱空間?
這樣的東西不起作用,但將由Eclipse驗證:
<import namespace="http://www.whatever.gov" location="../wherever" />
<import namespace="http://www.whatever.gov" location="../folder/superawesomeschema.xsd" />
很多人以前遇到過這類問題。 無論出於何種原因,只要您的驗證器沒有加載您希望它加載的架構文檔(並認為它正在加載),它就會出現。
要確認診斷:嘗試在ObjectHistory_1_0.xsd中引入錯誤(例如,格式錯誤),並查看系統是否抱怨。
使用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/endorsed
和創建jaxp.properties
在文件<jdk-home>/jre
包含行
javax.xml.validation.SchemaFactory\:http\://www.w3.org/2001/XMLSchema=org.apache.xerces.jaxp.validation.XMLSchemaFactory
我在執行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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.