Java SAXParseException; src-resolve:无法将名称“...”解析为(n)“类型定义”组件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18853890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SAXParseException; src-resolve: Cannot resolve the name '...' to a(n) 'type definition' component
提问by Mac
I'm trying to do schema validation, currently using a javax.xml.validation.SchemaFactory
. Unfortunately When I call the newSchema(Source schema)
function, I get the following error:
我正在尝试进行模式验证,目前使用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
The utility:ObjectStatusDateType
element is used in the .xsd file which I am passing into the newSchema(Source schema)
function. I am importing the ObjectStatusDateType
from another .xsd file- for which I have tripple checked the file path. The utility
namespace is also declared properly.
该utility:ObjectStatusDateType
元素在我传递给newSchema(Source schema)
函数的 .xsd 文件中使用。我正在ObjectStatusDateType
从另一个 .xsd 文件导入 -我已经三重检查了文件路径。该utility
命名空间还正确声明。
Here's a snippet of the schema I am passing into the function (LocateCoverageIndexesByIdentifier_3_0.xsd):
这是我传递给函数的模式片段 (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"/>
And this is from ObjectHistory_1_0.xsd:
这是来自 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>
And lastly, the bean
最后,豆
<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>
Has anybody encountered this type of issue before?
有没有人遇到过这种类型的问题?
采纳答案by CSum
I've had this issue before. Everything validated in Eclipse, but broke when running. Do any of your schemas import more than one schema into the same namespace?
我以前有过这个问题。一切都在 Eclipse 中得到验证,但在运行时坏了。您的任何架构是否将多个架构导入同一个命名空间?
Something like this will not work, but will be validated by Eclipse:
像这样的事情是行不通的,但会被 Eclipse 验证:
<import namespace="http://www.whatever.gov" location="../wherever" />
<import namespace="http://www.whatever.gov" location="../folder/superawesomeschema.xsd" />
回答by C. M. Sperberg-McQueen
Lots of people have encountered this type of issue before. It comes up whenever your validator is, for whatever reason, not loading the schema documents you want it to load (and think it's loading).
很多人以前都遇到过这种类型的问题。无论出于何种原因,只要您的验证器未加载您希望它加载的架构文档(并认为它正在加载),它就会出现。
To confirm the diagnosis: try introducing an error -- say, a well-formedness error -- into ObjectHistory_1_0.xsd, and see if the system complains.
要确认诊断:尝试在 ObjectHistory_1_0.xsd 中引入一个错误——比如说,一个格式良好的错误,然后看看系统是否有抱怨。
回答by Adrien Vercoutere
Using Xerces this can solved by setting the feature
http://apache.org/xml/features/honour-all-schemaLocations
to true.
使用 Xerces 可以通过将特性设置http://apache.org/xml/features/honour-all-schemaLocations
为 true来解决这个问题
。
The feature http://apache.org/xml/features/honour-all-schemaLocations
is only available
from Xerces 2.7.0. Current releases of Java 5.0 and 6.0 have a Xerces 2.6.2
built-in. Hence one has to use a newer Xerces library in order for this to work,
ie. copying xml-apis.jar
and xercesImpl.jar
to <jdk-home>/jre/lib/endorsed
and
creating a jaxp.properties
file in <jdk-home>/jre
containing the line
该功能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
回答by Aurelius Baier
I had the same problem when executing the maven plugin jaxb2-maven-plugin. After explicitly mentionning the xsd file to parse, it worked like a charm:
我在执行 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>