Hi Ravi, You can use the same unmarshalling context for both <employee> and <customer> objects, as long as they're both defined in the same binding.
Specifying a class when getting the factory is just a way for JiBX to find the binding information. Once it's found the binding information, the same factory and contexts can be used for all the <mapping>s included in the binding. I've actually added another way of looking up the binding information in the code for the upcoming 1.1.4 release, by passing in the name and package attributes from the <binding> element. - Dennis Dennis M. Sosnoski SOA and Web Services in Java Training and Consulting http://www.sosnoski.com - http://www.sosnoski.co.nz Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117 Ravikumar Tadysetty wrote: > >From the mailinglist archives, I found the following solution to read > one employee record at a time: > > <persons> > <employee>...</employee> > <employee>...</employee> > > <customer>...</customer> > <customer>...</customer> > > <consultant>...</consultant> > ... > </persons> > > IBindingFactory bfact = > BindingDirectory.getFactory(Employee.class); > IUnmarshallingContext uctx = > bfact.createUnmarshallingContext(); > uctx.setDocument(new FileInputStream("person.xml"), null); > > UnmarshallingContext umCtx = (UnmarshallingContext)uctx; > > umCtx.parsePastStartTag("", "persons"); > while(!umCtx.isEnd()) { > Object obj = umCtx.unmarshalElement(); > Employee emp = (Employee)obj; > } > > However, If I have to read the customer information also, then I have > to create another binding factory and restart. So it will be 2 passes > on the whole file. Is it possible to change the binding class name on > the binding factory so that I can use the same unmarshalling context > to extract Customer information. > > Thanks > Ravi > > > > > On 3/20/07, *Stephan Bourges* <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> wrote: > > >From my experience with JiBX, you could only load employee > information > (and drop the consultant, customer,etc.), but you will load all > employee. If you want to really reduce the three, maybe a Xquery > first > and then parse the resulting tree with JiBX?! > > To have JiBX ignore the other elements from the XML, just don't > put them > in the Binding file. > > -----Original Message----- > From: [EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]> > [mailto:[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>] On Behalf Of > ravikumar > Sent: Monday, March 19, 2007 1:28 PM > To: [email protected] > <mailto:[email protected]> > Subject: [jibx-users] JiBX- Binding only a part of the document > > > Hi, I have an xml document with different pieces of information. eg., > persons.xml below contains a list of employees ,a list of > customers, a > list of consultants, etc.. > <persons> > <employee>...</employee> > <employee>...</employee> > > <customer>...</customer> > <customer>...</customer> > > <consultant>...</consultant> > ... > </persons> > > I want to bind and read only the employee elements. > > This file is huge. At runtime, I don't want to load the whole file > into > memory at the same time. Is it possible to load these employee > elements > one at a time OR in small groups. I read that something could be done > like a call-back. But I am more looking for a pull mechanism where > I can > read elements on demand. > > Please let me know if this is possible. > > Regards > Ravi > -- > View this message in context: > http://www.nabble.com/JiBX--Binding-only-a-part-of-the-document-tf342857 > > 9.html#a9556805 > Sent from the jibx-users mailing list archive at Nabble.com > <http://Nabble.com>. > > > ------------------------------------------------------------------------ > - > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE> > V > _______________________________________________ > jibx-users mailing list > [email protected] > <mailto:[email protected]> > https://lists.sourceforge.net/lists/listinfo/jibx-users > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > _______________________________________________ > jibx-users mailing list > [email protected] > <mailto:[email protected]> > https://lists.sourceforge.net/lists/listinfo/jibx-users > <https://lists.sourceforge.net/lists/listinfo/jibx-users> > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > jibx-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jibx-users > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users
