Hi,Keith Thanx for this Keith. OK How do i forward desired elements to the UnmarshallHandler(). Is it using the StartElement() method. Also do i need to make some changes to my object source codes A.java & B.java (currently they just have simple get,set methods). Will the code snippet be something like this - Unmarshaller unmar = new Unmarshaller(B.class); UnmarshalHandler umh = unmar.createHandler(); umh.startElement(params...); umh.getCurrentObject(); This did not work properly...can u lemme know about this too..
Thanx in Advance! Regards, Anuj -----Original Message----- From: Keith Visco [mailto:[EMAIL PROTECTED] Sent: 02 December 2003 21:45 To: [EMAIL PROTECTED] Subject: Re: [castor-dev] UnMarshalling specific object types... 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 ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
