S2
From: Keith Visco <[EMAIL PROTECTED]> Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: [castor-dev] UnMarshalling specific object types... Date: Tue, 02 Dec 2003 14:45:14 -0600
Anuj,
See inline below...
"Sharma Anut (external)" wrote:
>
> Hi,All
>
> Can some one lemme know about this one....Will Appreciate if someone can
> lemme know about this...
>
> How to fetch Objects of specific type other than the root element directly
> using the Unmarshall Method.
>
> Example my XML file is say (A.xml) -
> <A>
> <B>
> <color>"Red"</colr>
> </B>
> </A>
>
> Mapping file is say (map.xml)-
> <mapping>
> <class name="A">
> <map-to xml="A"/>
> <field name="B" type="B">
> <bind-xml name="B" node="element"/>
> </field>
> </class>
> <class name="B">
> <field name="color" type="java.lang.String">
> <bind-xml name="color" node="element"/>
> </field>
> </class>
> <mapping>
>
> Then when i do the following to fetch B directly -
> Mapping mapping = new Mapping();
> mapping.loadMapping("map.xml");
> Unmarshaller unmar = new Unmarshaller(B.class);
> obj = unmar.unmarshal(new InputSource(new FileReader(strInXML)));
> OR
> Unmarshaller.unmarshal(B.class,new InputSource(new FileReader(strInXML)));
>
> I get a NullPointer Exception.
>
> Can someone lemme know how do i go about fetching B directly without
> fetching A(root element) then doing a getObject on it for B.(This way it
> works)
If you pass in class B to the Unmarshaller it will try to use "B" as the root and hence it will try to map element A to your class B and that explains the problems you are having when you try to do that.
Castor currently doesn't have a built-in mechanism for stripping off unwanted elements. You can do this yourself with a ContentHandler and forwarding only your desired elements on to Castor's UnmarshalHandler (see Unmarshaller#createHandler).
--Keith
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
_________________________________________________________________
Dale rienda suelta a tu tiempo libre. Encuentra mil ideas para exprimir tu ocio con MSN Entretenimiento. http://entretenimiento.msn.es/
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
