私はjibx libを使用してxsdをJavaコードに生成しています。antを使用してjarファイルも作成しました。xmlschemalocation を設定する必要がある場合、以下のように marshalmessage を実行すると、xsd の場所を取得できます。
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;
}
//これは、オブジェクトの作成に使用されます
DeviceCapability devicecapability = new DeviceCapability();
devicecapability.setHref("Hello");
String xml = marshalMessage(devicecapability);
生成された xml o/p は ?xml version="1.0" encoding="UTF-8"?> /DeviceCapability xmlns="http://zigbee.org/sep" href="Hello"//>
以下のような o/p が欲しい ?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/>
jibx を使用して schemalocation を追加する方法を誰か教えてもらえますか。Ant codegen/bind ツールを使用しました。