[castor-dev] Unmarshalling with namespace BUG

J p <[email protected]> Sun, 29 Apr 2012 09:41:28 +0530
Newsgroups gmane.comp.java.castor.devel
Message-ID <CAGDpBkdNaBco0pbkBYCe=nKgJf=zxYvAU7apHSnN=z5CQ7OkZQ__25123.6093150967$1335672717$gmane$org@mail.gmail.com>
--047d7b33da181f289104bec988cb
Content-Type: text/plain; charset=ISO-8859-1

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
>
>

--047d7b33da181f289104bec988cb
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Werner,<br><br>I am having a problem when Unmarshalling with=20
namespace. The problem is the xml elements are not binding to java=20
classes when unMarshalling.<br><br>unMarshalling is success if i give names=
pace prefix.<br>
<br>Please provide a solution for the problem. The XML which i am=20
unmarshalling is given by our client. I don&#39;t have access to edit/modif=
y
 the XML file.<br><br>The xml given by our client doesn&#39;t have any name=
space prefixes.<br><br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3DXML without namepa=
ce prefix (not working )=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D<br><br><span style=3D"color:rgb(255,0,0)">Unmarshalling the xml without=
 namespace prefix throws <b><font>nullPointerException</font></b> when i tr=
y to acces the elements.</span><br>

<br>&lt;?xml version=3D&quot;1.0&quot; encoding=3D&quot;UTF-8&quot;?&gt;<br=
><br>&lt;Globus xmlns=3D&quot;<a href=3D"http://test.com" target=3D"_blank"=
>http://test.com</a>&quot; <br>xmlns:xsi=3D&quot;<a href=3D"http://www.w3.o=
rg/2001/XMLSchema-instance" target=3D"_blank">http://www.w3.org/2001/XMLSch=
ema-instance</a>&quot; <br>

xsi:schemaLocation=3D&quot;E:\\<blockquote class=3D"gmail_quote">castor\\sa=
mple.xsd&quot;&gt;<br><br>&lt;serviceResponse&gt;<br>&lt;ofsStandardEnq nam=
e=3D&quot;BALANCES&quot; /&gt;<br>&lt;/serviceResponse&gt;<br><br>&lt;/Glob=
us&gt;<br>
<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =
End =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
<br><br>
<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3DXML with namepace prefix (works fine ) =3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
<br><span style=3D"color:rgb(255,102,102)">Unmarshalling the xml with names=
pace prefix works fine</span><br><br>
&lt;?xml version=3D&quot;1.0&quot; encoding=3D&quot;UTF-8&quot;?&gt;<br>
<br>
&lt;Globus xmlns:g=3D&quot;<a href=3D"http://test.com" target=3D"_blank">ht=
tp://test.com</a>&quot; <br>
xmlns:xsi=3D&quot;<a href=3D"http://www.w3.org/2001/XMLSchema-instance" tar=
get=3D"_blank">http://www.w3.org/2001/XMLSchema-instance</a>&quot; <br>
xsi:schemaLocation=3D&quot;E:\\castor\\sample.xsd&quot;&gt;<br>
<br>
&lt;serviceResponse&gt;<br>
&lt;ofsStandardEnq name=3D&quot;BALANCES&quot; /&gt;<br>
&lt;/serviceResponse&gt;<br>
<br>
&lt;/Globus&gt;<br>
<br>
<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D END =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D CastorTest Class=A0 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br><br>=A0=A0=A0=A0=
=A0=A0=A0 XMLContext context =3D new XMLContext();<br>=A0=A0=A0 =A0=A0=A0 U=
nmarshaller unMarshaller =3D=A0=A0=A0 context.createUnmarshaller();<br>

=A0=A0=A0 =A0=A0=A0 Mapping mapping =3D new Mapping();<br>=A0=A0=A0 =A0=A0=
=A0 mapping.loadMapping(&quot;E:/castor/mapping_res.xml&quot;);<br>=A0=A0=
=A0 =A0=A0=A0 unMarshaller.setMapping(mapping);<br>=A0=A0=A0 =A0=A0=A0 unMa=
rshaller.setClass(Globus.class);<br>=A0=A0=A0 =A0=A0=A0 unMarshaller.setVal=
idation(false);<br>

=A0=A0=A0 =A0=A0=A0 //unMarshaller.setProperty(&quot;org.exolab.castor.pars=
er.namespaces&quot;, &quot;false&quot;);<br>=A0=A0=A0 =A0=A0=A0 Reader read=
er =3D new FileReader(&quot;E:/castor/SAMPLE.xml&quot;);<br>=A0=A0=A0 =A0=
=A0=A0 Globus g =3D (Globus)unMarshaller.unmarshal((reader));<br>

<br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D END =3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D Mapping XML =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>&lt;?xm=
l version=3D&quot;1.0&quot; encoding=3D&quot;UTF-8&quot;?&gt;<br><br>&lt;ma=
pping xmlns:xsi=3D&quot;<a href=3D"http://www.w3.org/2001/XMLSchema-instanc=
e" target=3D"_blank">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br=
>

=A0=A0=A0=A0=A0=A0=A0=A0 xmlns=3D&quot;<a href=3D"http://castor.exolab.org/=
" target=3D"_blank">http://castor.exolab.org/</a>&quot;<br>=A0=A0=A0=A0=A0=
=A0=A0=A0 xsi:schemaLocation=3D&quot;<a href=3D"http://castor.exolab.org/ma=
pping.xsd" target=3D"_blank">http://castor.exolab.org/mapping.xsd</a>&quot;=
&gt;<br>

<br>=A0=A0=A0 &lt;class name=3D&quot;com.gen.Globus&quot;&gt;<br>=A0=A0=A0 =
&lt;map-to ns-uri=3D&quot;<a href=3D"http://test.com" target=3D"_blank">htt=
p://test.com</a>&quot;/&gt;<br>=A0=A0=A0 =A0=A0=A0 <br>=A0=A0=A0 =A0=A0=A0 =
&lt;field name=3D&quot;globusChoice&quot; type=3D&quot;com.gen.GlobusChoice=
&quot; container=3D&quot;true&quot; /&gt;<br>

=A0=A0=A0 &lt;/class&gt;<br><br>=A0=A0=A0 &lt;class name=3D&quot;com.gen.Gl=
obusChoice&quot;&gt;<br>=A0=A0=A0 =A0=A0=A0 &lt;field name=3D&quot;serviceR=
esponse&quot; type=3D&quot;com.gen.ServiceResponse&quot;&gt;<br>=A0=A0=A0 =
=A0=A0=A0 &lt;bind-xml name=3D&quot;serviceResponse&quot;/&gt;<br>

=A0=A0=A0 =A0=A0=A0 &lt;/field&gt;<br>=A0=A0=A0 =A0=A0=A0 <br>=A0=A0=A0 &lt=
;/class&gt;<br><br>=A0&lt;class name=3D&quot;com.gen.ServiceResponse&quot; =
extends=3D&quot;com.OfsmlServiceResponse&quot;&gt;<br>=A0=A0=A0 =A0=A0=A0 =
=A0&lt;field name=3D&quot;ofsml12ServiceResponses&quot; type=3D&quot;com.ge=
n.Ofsml12ServiceResponses&quot; container=3D&quot;true&quot; /&gt;<br>

=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0 &lt;/class&gt;<br>=A0=A0=A0 <br>=A0=A0=A0 =
&lt;class name=3D&quot;com.fgb.fbp.gen.<blockquote class=3D"gmail_quote">Se=
rviceResponse&quot; extends=3D&quot;com.gen.SmlServiceResponse&quot;&gt;<br=
>=A0=A0=A0 =A0=A0=A0 =A0&lt;field name=3D&quot;sml1ServiceResponses&quot; t=
ype=3D&quot;com.gen.Sml1ServiceResponses&quot; container=3D&quot;true&quot;=
 /&gt;<br>


=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0 &lt;/class&gt;<br>=A0=A0=A0 <br>=A0=A0=A0 =
&lt;class name=3D&quot;com.gen.Sml1ServiceResponses&quot;&gt;<br>=A0=A0=A0 =
&lt;field name=3D&quot;ofsStandardEnq&quot; type=3D&quot;com.gen.OfsStandar=
dEnq&quot;&gt;<br>
=A0=A0=A0 &lt;bind-xml name=3D&quot;ofsStandardEnq&quot; /&gt;<br>=A0=A0=A0=
 &lt;/field&gt;<br>=A0=A0=A0 &lt;/class&gt;<br><br>=A0=A0=A0 &lt;class name=
=3D&quot;com.gen.OfsStandardEnq&quot; extends=3D&quot;com.OfsmlStandardEnqR=
esponse&quot;&gt;

=A0=A0=A0 &lt;field name=3D&quot;name&quot; type=3D&quot;java.lang.String&q=
uot;=A0 &gt;<br>=A0=A0=A0 &lt;bind-xml name=3D&quot;name&quot; node=3D&quot=
;attribute&quot; /&gt;<br>=A0=A0=A0 &lt;/field&gt;<br>
=A0=A0=A0 <br>=A0=A0=A0 &lt;/class&gt;</blockquote><br>=A0=A0=A0 <br>&lt;/m=
apping&gt;<br><br><br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D end =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br><br><br=
>Thanks IN aDVANCE<br><br></blockquote>

--047d7b33da181f289104bec988cb--