@xmlSchema annotation use with jaxb @xmlSchema annotation use with jaxb xml xml

@xmlSchema annotation use with jaxb


You can write out a schema location as follows:

Marshaller marshaller = jc.createMarshaller();marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://es.indra.transporte.configuration StationNetwork.xsd");marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);marshaller.marshal(root, System.out);

Running the following code:

import javax.xml.bind.JAXBContext;import javax.xml.bind.Marshaller;public class Demo {    public static void main(String[] args) throws Exception {        JAXBContext jc = JAXBContext.newInstance(StationNetwork.class);        StationNetwork root = new StationNetwork();        Marshaller marshaller = jc.createMarshaller();        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://es.indra.transporte.configuration StationNetwork.xsd");        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);        marshaller.marshal(root, System.out);    }}

Output - Metro (JAXB RI)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><stationNetwork     xmlns:com="http://es.indra.transporte.common"      xmlns:ns2="http://es.indra.transporte.configuration"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://es.indra.transporte.configuration StationNetwork.xsd"/>

Output - EclipseLink JAXB (MOXy)

<?xml version="1.0" encoding="UTF-8"?><stationNetwork     xsi:schemaLocation="http://es.indra.transporte.configuration StationNetwork.xsd"     xmlns:ns2="http://es.indra.transporte.configuration"     xmlns:com="http://es.indra.transporte.common"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>