JAXB External Custom Binding XJC Issue - Parsing results in empty node

juniorbansal picture juniorbansal · Jan 24, 2011 · Viewed 21.7k times · Source

Forgive me if this is a duplicate. Here is my binding.xjb file. But now i am getting the regular error that the complex type target "AddBankVaultRplyType" is not found. I don't see any issue. Can somebody help me with this? I am listing the xsd that i am trying to customize

<jxb:bindings 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:pd="http://chubb.com/cpi/polsvc/xmlobj"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance"
jxb:version="2.1"
>


<jxb:bindings node="/xs:schema/xs:ServiceReply/xs:complexType[@name='AddBankVaultRplyType']">
<inheritance:extends>com.print.poc.AddressTypeHelper</inheritance:extends>
</jxb:bindings>

Here is the piece of XSD that i am trying to customize

<xs:schema xmlns:pd="http://com/polsvc/xmlobj" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://com/polsvc/xmlobj" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="AddBankVaultRplyType">

</xs:complexType>
<xs:element name="ServiceReply">
   <xs:complexType>
   <xs:sequence>
    <xs:element name="ReplyHeader" type="pd:MsgHeaderType"/>
    <xs:element name="RequestHeader" type="pd:MsgHeaderType"/>
    <xs:choice>
     <xs:element name="AddBankVaultReply" type="pd:AddBankVaultRplyType"/>
</xs:choice>
 </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

Now if i run XJC it is saying me that the target "/xs:schema/xs:ServiceReply/xs:complexType[@name='AddBankVaultRplyType']" results in empty node. What is the mistake i am doing here

Answer

bdoughan picture bdoughan · Jan 24, 2011

You will need to wrap in a bindings that has the schema location set. It should be something like:

<jxb:bindings 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:pd="http://chubb.com/cpi/polsvc/xmlobj"
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
    jxb:extensionBindingPrefixes="inheritance"
    version="2.1">
    <jxb:bindings schemaLocation="your-schema.xsd">
        <jxb:bindings node="//xs:complexType[@name='AddBankVaultRplyType']">
            <inheritance:extends>com.print.poc.AddressTypeHelper</inheritance:extends>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

For more information: