Discussions

XML & Web services: XML databinding question

  1. XML databinding question (2 messages)

    Looking for possible databinding options which would bind(map) a xml instance doc(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 : Instance doc: Joe Trader 10 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; } ]
  2. You can do what you want with Castor and JAXB, although it requires some digging through the documentation. It may also be possible with XMLBeans, but I don't know for sure. Alternatively, JiBX (jibx.sf.net) is designed specifically for binding from Schemas to existing Java classes (although it too can create a set of Java classes from scratch to represent a Schema, when required). Cheers, Tony. Advanced XML Applications http://www.amazon.com/XML-Power-Comprehensive-Guide-Guides/dp/1598632140/
  3. There're many solutions[ Go to top ]

    There're many binding apis to do so. Programatically you can use XStream from codehaus, it's a very intuitive api, and very easy to use (There's a two minute tutorial). But if you want to make a huge aplication where you want to plan everything from the beginning you'd better use XmlBeans or JAXB. In my opinion XmlBeans is easier to use but... hey check them out and then choose.