Reputation: 16233
I have this class
@XmlRootElement
public class GpsDataRequest{
//definition of variables
@XmlElement(required=true, type=GpxType.class)
public GpxType getGpxRoot() {
return gpxRoot;
}
@XmlElement(required=true, type=JourneyXML.class)
public JourneyXML getJourneyPlanRoot() {
return journeyPlanRoot;
}
@XmlElement(required=true)
public String getSecurityToken() {
return securityToken;
}
@XmlElement(required=true)
public UUID getUuid() {
return uuid;
}
}
When i generate the schema using this code:
public class SchemaGenerator {
public static void main(String[] args)
{
try {
JAXBContext context=
JAXBContext.newInstance(GpsDataRequest.class);
SchemaOutputResolver sor =new DemoSchemaOutputResolver();
context.generateSchema(sor);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static class DemoSchemaOutputResolver extends SchemaOutputResolver {
@Override
public Result createOutput(String namespaceUri, String suggestedFileName)
throws IOException {
// create new file
File file = new File("request.xsd");
// create stream result
StreamResult result = new StreamResult(file);
// set system id
result.setSystemId(file.toURI().toURL().toString());
// return result
return result;
}
}
}
All I get is the XSD of the GpxType class only. Why is that?
Just to let you know, GpxType and JourneyXML are generated from XSD files.
How to enforce this to generate the appropriate XSD I need?
Upvotes: 3
Views: 623
Reputation: 148977
Try changing your createOutput
method to not always write to the request.xsd
file. I believe there are multiple namespaces in your model and therefore multiple XML schemas are being generated.
@Override
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
// create new file
File file = new File(suggestedFileName);
// create stream result
StreamResult result = new StreamResult(file);
// set system id
result.setSystemId(file.toURI().toURL().toString());
// return result
return result;
}
Upvotes: 1