[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't have access to edit/modif=
y
the XML file.<br><br>The xml given by our client doesn'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><?xml version=3D"1.0" encoding=3D"UTF-8"?><br=
><br><Globus xmlns=3D"<a href=3D"http://test.com" target=3D"_blank"=
>http://test.com</a>" <br>xmlns:xsi=3D"<a href=3D"http://www.w3.o=
rg/2001/XMLSchema-instance" target=3D"_blank">http://www.w3.org/2001/XMLSch=
ema-instance</a>" <br>
xsi:schemaLocation=3D"E:\\<blockquote class=3D"gmail_quote">castor\\sa=
mple.xsd"><br><br><serviceResponse><br><ofsStandardEnq nam=
e=3D"BALANCES" /><br></serviceResponse><br><br></Glob=
us><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>
<?xml version=3D"1.0" encoding=3D"UTF-8"?><br>
<br>
<Globus xmlns:g=3D"<a href=3D"http://test.com" target=3D"_blank">ht=
tp://test.com</a>" <br>
xmlns:xsi=3D"<a href=3D"http://www.w3.org/2001/XMLSchema-instance" tar=
get=3D"_blank">http://www.w3.org/2001/XMLSchema-instance</a>" <br>
xsi:schemaLocation=3D"E:\\castor\\sample.xsd"><br>
<br>
<serviceResponse><br>
<ofsStandardEnq name=3D"BALANCES" /><br>
</serviceResponse><br>
<br>
</Globus><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("E:/castor/mapping_res.xml");<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("org.exolab.castor.pars=
er.namespaces", "false");<br>=A0=A0=A0 =A0=A0=A0 Reader read=
er =3D new FileReader("E:/castor/SAMPLE.xml");<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><?xm=
l version=3D"1.0" encoding=3D"UTF-8"?><br><br><ma=
pping xmlns:xsi=3D"<a href=3D"http://www.w3.org/2001/XMLSchema-instanc=
e" target=3D"_blank">http://www.w3.org/2001/XMLSchema-instance</a>"<br=
>
=A0=A0=A0=A0=A0=A0=A0=A0 xmlns=3D"<a href=3D"http://castor.exolab.org/=
" target=3D"_blank">http://castor.exolab.org/</a>"<br>=A0=A0=A0=A0=A0=
=A0=A0=A0 xsi:schemaLocation=3D"<a href=3D"http://castor.exolab.org/ma=
pping.xsd" target=3D"_blank">http://castor.exolab.org/mapping.xsd</a>"=
><br>
<br>=A0=A0=A0 <class name=3D"com.gen.Globus"><br>=A0=A0=A0 =
<map-to ns-uri=3D"<a href=3D"http://test.com" target=3D"_blank">htt=
p://test.com</a>"/><br>=A0=A0=A0 =A0=A0=A0 <br>=A0=A0=A0 =A0=A0=A0 =
<field name=3D"globusChoice" type=3D"com.gen.GlobusChoice=
" container=3D"true" /><br>
=A0=A0=A0 </class><br><br>=A0=A0=A0 <class name=3D"com.gen.Gl=
obusChoice"><br>=A0=A0=A0 =A0=A0=A0 <field name=3D"serviceR=
esponse" type=3D"com.gen.ServiceResponse"><br>=A0=A0=A0 =
=A0=A0=A0 <bind-xml name=3D"serviceResponse"/><br>
=A0=A0=A0 =A0=A0=A0 </field><br>=A0=A0=A0 =A0=A0=A0 <br>=A0=A0=A0 <=
;/class><br><br>=A0<class name=3D"com.gen.ServiceResponse" =
extends=3D"com.OfsmlServiceResponse"><br>=A0=A0=A0 =A0=A0=A0 =
=A0<field name=3D"ofsml12ServiceResponses" type=3D"com.ge=
n.Ofsml12ServiceResponses" container=3D"true" /><br>
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0 </class><br>=A0=A0=A0 <br>=A0=A0=A0 =
<class name=3D"com.fgb.fbp.gen.<blockquote class=3D"gmail_quote">Se=
rviceResponse" extends=3D"com.gen.SmlServiceResponse"><br=
>=A0=A0=A0 =A0=A0=A0 =A0<field name=3D"sml1ServiceResponses" t=
ype=3D"com.gen.Sml1ServiceResponses" container=3D"true"=
/><br>
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0 </class><br>=A0=A0=A0 <br>=A0=A0=A0 =
<class name=3D"com.gen.Sml1ServiceResponses"><br>=A0=A0=A0 =
<field name=3D"ofsStandardEnq" type=3D"com.gen.OfsStandar=
dEnq"><br>
=A0=A0=A0 <bind-xml name=3D"ofsStandardEnq" /><br>=A0=A0=A0=
</field><br>=A0=A0=A0 </class><br><br>=A0=A0=A0 <class name=
=3D"com.gen.OfsStandardEnq" extends=3D"com.OfsmlStandardEnqR=
esponse">
=A0=A0=A0 <field name=3D"name" type=3D"java.lang.String&q=
uot;=A0 ><br>=A0=A0=A0 <bind-xml name=3D"name" node=3D"=
;attribute" /><br>=A0=A0=A0 </field><br>
=A0=A0=A0 <br>=A0=A0=A0 </class></blockquote><br>=A0=A0=A0 <br></m=
apping><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--