Link to home
Start Free TrialLog in
Avatar of blackfrancis75
blackfrancis75

asked on

jaxb; 2 schemas with common xs:import

Hello,
I am using JAXB in my j2ee project.
I have two XML Schemas; Report.xsd and Graph.xsd
Both of these schemas import a common element defined in Query.xsd
I can generate the Java classes to represent these schemas using Jaxb an manipulate DOMs an so on, no problem.
The probelm is; I thought by having both Report and Graph import Query, that when I called:
 graph.getQuery().get( 0 );
or:
 report.getQuery().get( 0 );
that I'd get back an object of type:
 com.mycompany.myproject.query.Query;
but what I actually get back is a:
 com.mycompany.myproject.graph.Query;
or:
 com.mycompany.myproject.report.Query;
depending on which object I called on.
This is frustrating because I expected both Report and Graph to use objects with the same interface so I could process the Query irrespective of whether it was a Report query or a Graph query.
The generated report.Query and graph.Query don't even implement any interface in common.
Could someone advise me how to achieve what I'm trying to do?  Is there a way to tweak JAXB to do this?
Cheers,

Avatar of astorer
astorer

Are you using namespaces in the XSDs ?  I'd suggest you should be.
What namespace do you use for each XSD and can you show the actual import statements that you use in each?
Avatar of blackfrancis75

ASKER

sorry, I meant that I was including the query schema, not importing it.
Both report.xsd and graph.xsd have the line:
<xs:include schemaLocation="./query.xsd" ></xs:include>
at the top.
Will changing this to an xs:import statement and using a different namespace result in the desired common interface I'm after?  
I don't understand how that would work..
If I use xs:import instead of xs:include, I get a parse error in my Report.xsd in the section:
  <xs:sequence>
    <xs:element ref="query" maxOccurs="unbounded"/>
  </xs:sequence>

"cannot resolve the name 'query' to a(n) 'element declaration' component"
ASKER CERTIFIED SOLUTION
Avatar of astorer
astorer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial