Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

[castor-user] Multiple nodes with the same name and an ns-uri

Cass, Derek

2012-11-27


Author LoginPost Reply
Hello list.  I am quite new to castor, so please bear with me if this has been answered before.  I searched the mailing list and came up empty, but I may just not know how to ask the question correctly.
 
I have the following (heavily pared down) xml response that I need to unmarshall via castor:
 
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Body>
                <GetCustomerPrefillResponse xmlns="http://com.com/ns/ics/service/AcctOpen/2005-05">
                        <GetCustomerPrefillResponse>
                                <CustomerId>123456789</CustomerId>
                        </GetCustomerPrefillResponse>
                </GetCustomerPrefillResponse>
        </soap:Body>
</soap:Envelope>
 
Here is the mapping file that I have for tha above response:
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
                                                   "http://castor.org/mapping.dtd">
<mapping>
       <class name="com.com.impl.customerprefill.WebServiceResponse">
          <map-to xml="Envelope" ns-uri="http://schemas.xmlsoap.org/soap/envelope/" ns-prefix="soap" />
                  <field name="customerPrefillResponse" type="com.com.impl.customerprefill.CustomerPrefillResponse" required="false" direct="false">
                          <bind-xml name="GetCustomerPrefillResponse" node="element" location="Body" />
                  </field>
       </class>
       <class name="com.com.impl.customerprefill.CustomerPrefillResponse">
          <map-to xml="GetCustomerPrefillResponse" ns-uri="http://com.com/ns/ics/service/AcctOpen/2005-05" />
                <field name="customerId" type="java.lang.String"  required="false" direct="false">
                        <bind-xml name="CustomerId" node="element" location="GetCustomerPrefillResponse" />
                </field>
       </class>
</mapping>
 
The above mapping doesn't work for the above response.  I get no errors, but I get null for everything.  However, if I take out the 2nd GetCustomerPrefillResponse element from the xml and the mapping file, I will get CustomerId field from the response.  The below xml and mapping file does work:
 
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Body>
                <GetCustomerPrefillResponse xmlns="http://com.com/ns/ics/service/AcctOpen/2005-05">
                        <CustomerId>123456789</CustomerId>
                </GetCustomerPrefillResponse>
        </soap:Body>
</soap:Envelope>
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
                                                   "http://castor.org/mapping.dtd">
<mapping>
       <class name="com.com.impl.customerprefill.WebServiceResponse">
          <map-to xml="Envelope" ns-uri="http://schemas.xmlsoap.org/soap/envelope/" ns-prefix="soap" />
                  <field name="customerPrefillResponse" type="com.com.impl.customerprefill.CustomerPrefillResponse" required="false" direct="false">
                          <bind-xml name="GetCustomerPrefillResponse" node="element" location="Body" />
                  </field>
       </class>
       <class name="com.com.impl.customerprefill.CustomerPrefillResponse">
          <map-to xml="GetCustomerPrefillResponse" ns-uri="http://com.com/ns/ics/service/AcctOpen/2005-05" />
                <field name="customerId" type="java.lang.String"  required="false" direct="false">
                        <bind-xml name="CustomerId" node="element"/>
                </field>
       </class>
</mapping>
 
Unfortunately, I don't have control over the xml response, so I need to deal with the nested elements of the same name.  What am I missing here?  Any help would be greatly appreciated.
 
Thanks,
 
Derek
 
©2008 junlu.com - Jax Systems, LLC, U.S.A.