Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

XML databinding question

Thread view: 
udupi_mail@yahoo.com - 21 Dec 2006 04:44 GMT
Can anybody suggest possible databinding options which would bind(map)
xml instance docs(which conforms to some pre-defined xsd) to a
PRE-EXISTING java object (see below example). I looked at xstream which
seems to be a good option for serializing/deserializing objects to xml
and vice-versa(xstream does not care for schemas). Same with JAXB,
Castor or Xmlbeans ..I have not found a way to map the below xml to my
custom java obj?

Any pointers will be very helpful.

TIA,
Guru.

an e.g. would be :
<schema>
 <complexType>
   <sequence>
     <element name="name" type="string" />
     <element name="deptid" type="int" />
   </sequence>
 </complexType>
</schema>

Instance doc:
<employee>
    <name>Joe Trader</name>
    <deptid>10</deptid>
</employee>

Custom Java obj (with no default const., accessors or mutators):
public class Employee
{
 public final String name;
 public final int deptid;

 public Employee (String name, int deptid) // overloaded const.
 {
   this.name = name;
   this.deptid = deptid;
 }

}
Daniel Dyer - 21 Dec 2006 09:46 GMT
> Can anybody suggest possible databinding options which would bind(map)
> xml instance docs(which conforms to some pre-defined xsd) to a
[quoted text clipped - 3 lines]
> Castor or Xmlbeans ..I have not found a way to map the below xml to my
> custom java obj?

JiBX (http://jibx.sourceforge.net) should be able to map your example with  
no problems at all.  You should be able to find examples in the  
documentation.  JiBX works at a lower level than many of the alternative  
tools, so it does not need to rely on Java Beans conventions or  
reflection.  Instead there is an extra build step that injects bytecode  
into your classes.  This approach has the twin advantages of being  
non-invasive (at the source level) and very fast at runtime.

Dan.

Signature

Daniel Dyer
http://www.uncommons.org



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.