2

I'm running into a problem with some XML validation and am trying to debug my problem. I am generating my XSDs on the fly with JAXBContext.generateSchema(), and then creating a unified schema with SchemaFactory.newSchema(schemas). However, my validation is failing. I'd like to see if the unified schema that newSchema is creating is as I expect, however I cannot seem to find a way to export the resulting Schema class to a string or a text file.

Is there any way to export a javax.xml.validation.Schema class into a readable String and/or XSD file? I looked through the API and cannot seem to find anything.

Thanks,

Eric

Eric B.
  • 23,425
  • 50
  • 169
  • 316

1 Answers1

0

Instead of combining your schemas after creating them from JAXBContext.generateSchema(), why not just generate them all at once from your JAXBContext.

JAXBContext jc = JAXBContext.newInstance( new Class[] { Class1.class,
                                                        Class2.class,
                                                        Class3.class
                                                      }
                                        );
jc.generateSchema(new SchemaOutputResolver() {
    @Override
    public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
      File file = new File(suggestedFileName);
      return new StreamResult(file);
    }
});
Brant Olsen
  • 5,628
  • 5
  • 36
  • 53
  • It has been a while since I looked at this piece of the code, but you couldn't do that if you had multiple namespaces. The solution to generating multiple schemas with different namespaces can be found http://stackoverflow.com/a/2696765/827480. However, my issue at this point was getting them all resolved in the proper order. I ended up getting it to work (see http://stackoverflow.com/a/8885327/827480), but was still wondering if there was any way of exporting a unified schema. So far, haven't found a solution to that issue yet. – Eric B. Mar 30 '12 at 03:41