Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

java - JAXB SchemaFactory source order must follow import order between schemas?

Using latest JAXB (Sun) and have a hierarchy of schemas that use import directives between schemas to share type definitions. Schema validation is activated on the setSchema call to Marshaller/Unmarshaller in JAXB which should defer validation to Xerces (using Java 1.5). I don't want to know the order of import directives between schemas when creating the Schema object with SchemaFactory. Unfortunately, I haven't found a Xerces feature/property that allows for this. For example, if a.xsd is pulled into b.xsd with an import then the following code doesn't work:

FileInputStream a = new FileInputStream("a.xsd");
FileInputStream b = new FileInputStream("b.xsd");

Schema schema = SchemaFactory.newInstance(
   XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
      new Source[] { 
          new StreamSource(b),
          new StreamSource(a) 
      }
   );

The order of the Source array has to be a.xsd then b.xsd. Any way around this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What if you create a schema on the root Source, and then set a ResourceResolver (LSResourceResolver) to resolve the other imported schemas during the schema creation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...