Validating a JAXB schema when disassembling a non-root element

When you unmount all XML using JAXB, you can configure the XML schema to enable validation during parsing:

//javax.xml.validation.Schema schema = ... jaxbUnmarshaller = JAXBContext.newInstance(SomeRootType.class).createUnmarshaller(); jaxbUnmarshaller.setSchema(schema); 

On the other hand, when you cancel the NestedObjest list from XML, one after the other (for example, to reduce memory usage), this method fails (since Schema accepts only root) with the exception:

 org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 22; cvc-elt.1: Cannot find the declaration of element 'NestedObject' 

It fails even if NestedObjectType is clearly defined in XSD. Is it possible to enable scanning of nested objects? Please note that defining a new schema is pathetic, as the XSD is external to my application supported by someone else.

+8
java xml xsd jaxb
source share
1 answer

Have you tried passing an associated bean class to the unmarshal method? As described in Example 65. Unmarshalling into a known type

0
source share

All Articles