0
votes

I am using jibx lib to generate xsd to java code.I have created jar file as well using ant. Where we need to set xmlschemalocation so when we do marshalmessage as below we can get xsd location.

public String marshalMessage(Object message) 
    {
        try {
            IBindingFactory jc = BindingDirectory.getFactory(DeviceCapability.class);       

            IMarshallingContext marshaller = jc.createMarshallingContext();     

            ByteArrayOutputStream out = new ByteArrayOutputStream();        

            marshaller.marshalDocument(message, URL_ENCODING, null, out);
            return out.toString(STRING_ENCODING);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (JiBXException e) {
            e.printStackTrace();
        }
        return null;
    }

//This is used to create the object

DeviceCapability devicecapability  = new  DeviceCapability();
 devicecapability.setHref("Hello");
 String xml = marshalMessage(devicecapability);

Generated xml o/p is ?xml version="1.0" encoding="UTF-8"?> /DeviceCapability xmlns="http://zigbee.org/sep" href="Hello"//>

I want o/p like below ?xml version="1.0" encoding="UTF-8"?>DeviceCapability xmlns="http://zigbee.org/sep" href="Hello" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://zigbee.org/abc abc.xsd/>

Can someone tell me how to add schemalocation using jibx.I have used ant codegen/bind tools.

1

1 Answers

0
votes

JiBX easily handles multiple namespaces. All you have to do is specify all the namespaces in your schema definition (.xsd) file(s). For example, here's a snippet from one of my schema definitions:

<xs:import namespace="http://javafx.com" schemaLocation="javafx.xsd"/>
<xs:element name="jnlp">
<xs:complexType>
<xs:sequence>
<xs:element ref="information" maxOccurs="unbounded"/>
<xs:element ref="jfx:javafx-desc" minOccurs="0" maxOccurs="1"/>
</xs:sequence>

The JiBX generated XML has the namespace definitions that you want.

Don - JiBX contributor