SAXParseException; src-resolve: Cannot resolve the name '...' to a(n) 'type definition' component
Asked Answered
H

4

16

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:

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.

Here's a snippet of the schema I am passing into the function (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:

<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?

Heerlen answered 17/9, 2013 at 15:27 Comment(1)
I am facing the same issue. Were you able to resolve it? If so then what worked out for you?Langbehn
P
12

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?

Something like this will not work, but will be validated by Eclipse:

<import namespace="http://www.whatever.gov" location="../wherever" />
<import namespace="http://www.whatever.gov" location="../folder/superawesomeschema.xsd" />
Pyroelectricity answered 18/9, 2013 at 16:59 Comment(3)
This solved it. Sorry, I should have initially included more of the file in my first code tag (made that edit). I was including two xsd files under the sei.com/utility/1 namespace, one of which being the ObjectHistory_1_0.xsd. It's always the stupid stuff...Heerlen
sorry it wont work to validate when another namespace is included ?Clabber
Replace the attribute "location" with "schemaLocation" (see w3schools.com/xml/el_import.asp)Homology
T
6

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.

Tremolant answered 17/9, 2013 at 15:57 Comment(1)
You were right.. If I change something about ObjectHistory_1_0.xsd, the factory doesn't pick up the issueHeerlen
N
5

Using Xerces this can solved by setting the feature http://apache.org/xml/features/honour-all-schemaLocations to 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

javax.xml.validation.SchemaFactory\:http\://www.w3.org/2001/XMLSchema=org.apache.xerces.jaxp.validation.XMLSchemaFactory
Navigation answered 29/11, 2013 at 10:5 Comment(0)
T
4

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:

<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> 
Taxiplane answered 25/6, 2014 at 10:21 Comment(1)
This helps me also - explicitly point to exactly one xsd file (there are several xsd files in the same directory).Limner

© 2022 - 2024 — McMap. All rights reserved.