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.qu ery.Query;
but what I actually get back is a:
com.mycompany.myproject.gr aph.Query;
or:
com.mycompany.myproject.re port.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,
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.qu
but what I actually get back is a:
com.mycompany.myproject.gr
or:
com.mycompany.myproject.re
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,
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.xs d" ></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..
Both report.xsd and graph.xsd have the line:
<xs:include schemaLocation="./query.xs
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..
ASKER
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"
<xs:sequence>
<xs:element ref="query" maxOccurs="unbounded"/>
</xs:sequence>
"cannot resolve the name 'query' to a(n) 'element declaration' component"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What namespace do you use for each XSD and can you show the actual import statements that you use in each?