JAXB Marshaller with the specified schema

I want to define a schema in every XML file that I am building. And then get this schema (path string) in the unmarshalling process. marshaller.setSchema() only

Allows the caller to validate the marshalled XML as it is sorted.

Yes, I can write an extra bean for this purpose, but I want to get xml as

 <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='bla-bla.xsd'>... 
+4
source share
1 answer

To specify noNamespaceSchemaLocation, you can do the following:

 JAXBContext jc = JAXBContext.newInstance(Root.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "bla-bla.xsd"); 
+5
source

Source: https://habr.com/ru/post/1332534/


All Articles