XML databinding question

Discussion in 'XML' started by udupi_mail@yahoo.com, Dec 21, 2006.

  1. Guest

    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;
    }

    }
    , Dec 21, 2006
    #1
    1. Advertising

  2. Daniel Dyer Guest

    On Thu, 21 Dec 2006 04:44:30 -0000, <> wrote:

    > 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?


    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.

    --
    Daniel Dyer
    http://www.uncommons.org
    Daniel Dyer, Dec 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. raheel

    XML query and databinding

    raheel, Oct 25, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    396
    Kirk Allen Evans [MVP]
    Oct 27, 2003
  2. Replies:
    1
    Views:
    320
    Daniel Dyer
    Dec 21, 2006
  3. jobs
    Replies:
    0
    Views:
    1,620
  4. Earl Teigrob
    Replies:
    1
    Views:
    402
    Shravan
    Mar 1, 2004
  5. Erik Wasser
    Replies:
    5
    Views:
    452
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page