This is xxx.xsd, defining the outer element in the foo namespace:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:foo="http://foo.com"
targetNamespace="http://foo.com"
xmlns:bar="http://bar.com"
jaxb:version="2.0">
<xsd:import namespace="http://bar.com"
schemaLocation="yyy.xsd"/>
<xsd:complexType name="DataType">
<xsd:sequence>
<xsd:element ref="bar:childData"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="data" type="foo:DataType"/>
</xsd:schema>
And here is yyy.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
targetNamespace="http://bar.com"
xmlns:bar="http://bar.com"
jaxb:version="2.0">
<xsd:element name="childData" type="xsd:string"/>
</xsd:schema>
Later The usual Java code for marshalling:
void marshal() throws Exception {
JAXBContext jc = JAXBContext.newInstance( "com.foo:com.bar" );
Marshaller m = jc.createMarshaller();
DataType data = new DataType();
ObjectFactory of = new ObjectFactory();
JAXBElement<DataType> jbe = of.createData(data);
data.setChildData("child data");
m.marshal( jbe, System.out );
}
produces
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:data xmlns="http://bar.com" xmlns:ns2="http://foo.com">
<childData>child data</childData>
</ns2:data>
which is equivalent to the XML you have posted.