Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

[castor-user] Unmarshalling with namespace BUG

J p

2012-04-29


Author LoginPost Reply
Hi Werner,

I am having a problem when Unmarshalling with namespace. The problem is the xml elements are not binding to java classes when unMarshalling.

unMarshalling is success if i give namespace prefix.

Please provide a solution for the problem. The XML which i am unmarshalling is given by our client. I don't have access to edit/modify the XML file.

The xml given by our client doesn't have any namespace prefixes.


==========XML without namepace prefix (not working )==================

Unmarshalling the xml without namespace prefix throws nullPointerException when i try to acces the elements.

<?xml version="1.0" encoding="UTF-8"?>

<Globus xmlns="http://test.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="E:\\
castor\\sample.xsd">

<serviceResponse>
<ofsStandardEnq name="BALANCES" />
</serviceResponse>

</Globus>


====================== End =================================



==========XML with namepace prefix (works fine ) ========================

Unmarshalling the xml with namespace prefix works fine

<?xml version="1.0" encoding="UTF-8"?>

<Globus xmlns:g="http://test.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="E:\\castor\\sample.xsd">

<serviceResponse>
<ofsStandardEnq name="BALANCES" />
</serviceResponse>

</Globus>


======================= END ==================================


============== CastorTest Class  =================================


        XMLContext context = new XMLContext();
        Unmarshaller unMarshaller =    context.createUnmarshaller();
        Mapping mapping = new Mapping();
        mapping.loadMapping("E:/castor/mapping_res.xml");
        unMarshaller.setMapping(mapping);
        unMarshaller.setClass(Globus.class);
        unMarshaller.setValidation(false);
        //unMarshaller.setProperty("org.exolab.castor.parser.namespaces", "false");
        Reader reader = new FileReader("E:/castor/SAMPLE.xml");
        Globus g = (Globus)unMarshaller.unmarshal((reader));

===================== END =====================================

================== Mapping XML =================================

<?xml version="1.0" encoding="UTF-8"?>

<mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://castor.exolab.org/"
         xsi:schemaLocation="http://castor.exolab.org/mapping.xsd">

    <class name="com.gen.Globus">
    <map-to ns-uri="http://test.com"/>
       
        <field name="globusChoice" type="com.gen.GlobusChoice" container="true" />
    </class>

    <class name="com.gen.GlobusChoice">
        <field name="serviceResponse" type="com.gen.ServiceResponse">
        <bind-xml name="serviceResponse"/>
        </field>
       
    </class>

 <class name="com.gen.ServiceResponse" extends="com.OfsmlServiceResponse">
         <field name="ofsml12ServiceResponses" type="com.gen.Ofsml12ServiceResponses" container="true" />
             </class>
   
    <class name="com.fgb.fbp.gen.
ServiceResponse" extends="com.gen.SmlServiceResponse">
         <field name="sml1ServiceResponses" type="com.gen.Sml1ServiceResponses" container="true" />
             </class>
   
    <class name="com.gen.Sml1ServiceResponses">
    <field name="ofsStandardEnq" type="com.gen.OfsStandardEnq">
    <bind-xml name="ofsStandardEnq" />
    </field>
    </class>

    <class name="com.gen.OfsStandardEnq" extends="com.OfsmlStandardEnqResponse">     <field name="name" type="java.lang.String"  >
    <bind-xml name="name" node="attribute" />
    </field>
   
    </class>

   
</mapping>



======================= end ====================================



Thanks IN aDVANCE

©2008 junlu.com - Jax Systems, LLC, U.S.A.