Skip to main content

XML -> Java -> XML the xsi:schemaLocation is lost when using JAXB

3 replies [Last post]
unankadu
Offline
Joined: 2007-04-03

Hi Gurus,

When JAXB is used for round tripping XML -> Java -> XML the xsi:schemaLocation is lost in the XML file that is obtained. This is because this attribute is not a part of the XML schema the JAXB xjc compiler uses to generate the java classes.

Can you please help me on how to achieve this?

For example:

Below is the schema file, schema.xsd:

<?xml version='1.0' encoding='UTF-8'?>

Below is my xml file: conf.xml

<?xml version="1.0" encoding="UTF-8"?>

4000

If you see in the above xml file, 'schemaLocation' attribute is there. But when I convert the xds to java and then to xml, this 'schemaLocation' attribute is not there in the xml file.

Inorder to retain the 'schemaLocation' in my xml file, Where I need to add the same in the xsd file before converting it to java using xjc. Or is there any other way so that I can retain the same.

Thanks,
Kiran

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09
unankadu
Offline
Joined: 2007-04-03

Hi,

Thanks a lot for the information.

In my case, marshalling is done by JAXB ( written POJO and using getter and setter methods and annotations for converting the Java to XML). Still is it possible to set the schemaLocation ? If yes, how can I set the JAXB_SCHEMA_LOCATION. Can you point me to some samples. I tried to find out some , but it resulted in vain.

Is there any otherway to add the xsi:schemaLocation into the xml file. ie. during the conversion from xml->java, using[b] xjc:binding[/b]?? or by adding some schemaLocation related information into the [b]'package-info.java'[/b] so that it will be considered during the marshalling time.

Can you help me out in resolving this and if I have mentioned anything wrong plz pardon me, as I am new to this technology.

Thanks,
Kiran

Message was edited by: unankadu

kohsuke
Offline
Joined: 2003-06-09

This is a marshaller property, as documented in the javadoc. Set that to Marshaller before you perform marshalling.