What is the best approach to create XML from Java Objects

Discussions

XML & Web services: What is the best approach to create XML from Java Objects

  1. I have a graph of Java objects that I need to persist as XML. The main object contains individual attributes, Collections of JavaBeans, and Maps of Collection of JavaBeans. I am looking at several options:

    Domify
    JAXB
    JDOM

    Can someone share your experience about this? Are there other technologies that I should look into? Thanks.
  2. I have a graph of Java objects that I need to persist as XML. The main object contains individual attributes, Collections of JavaBeans, and Maps of Collection of JavaBeans. I am looking at several options:

    >
    > Domify
    > JAXB
    > JDOM
    >
    > Can someone share your experience about this? Are there other technologies that I should look into? Thanks.

    Ive used Castor and JDOM so far castor is the easiest of the two to use as it takes a file writer and a java bean and produces the xml files and to read it back it just as easy
  3. i would suggest JAXB to be right parsing method for parsing or writing an xml document.Compared to other API's which i earlier tried this looks very simple and easier to learn.

    Advantages
    1.Fast to learn becoz jaxb is been designed to provide very high level abstraction to process any xml document which implies the learning curve becomes shorter and not many people in development need to know about xml.
    2.High performance compared to other techniques.
    3.Code is maintainable,readable and error prone.
    4.Establishing tight control of xml struture using xml schema.
    5.Debugging is simpler.
    6.Standard becoz sun gives as a specification.

    Limitation:
    You need to learn xml schema which i feel worth learning.

    Let me share what development process we had created for an xml based application using jaxb technology.

    Process 1


    i appointed a person one who knows about xml schema,he was called as XMLDesigner
    one who only knows about how the xml struture would look like.His deliverable would be an xsd file which he would design and use a tool which would convert an xsd into javabean code.The tool basically is a code generater which reads the script from xsd file and converts into javabean containing getter,setters methods.Each getter,setter methods would map to the corresponding column in your xml document.
    </p>

    Process 2


    Next the code comes to a java developer one who integrate's the code with the application without knowing much about xml.
    </p>

    Experiance with XML technologies

    We had designed around 200 plus xml documents for various simple and complex xml strutures.
    Technologies used xerces api's,jaxp api's both dom and sax,jdom,jaxb.
    xml validators:DTD,xml schema
    </p>

    Shiva
  4. Thank you for sharing all the details, which are quite useful. I have the feeling that JAXB is the future direction. Even though there are a few opensource options (Castor, Quick, Domify see http://www-106.ibm.com/developerworks/xml/library/x-databd3/index.html) that are popular today. However, I do have the following quations:

    1. Do you find it somewhat limiting that Sun's JWSDP 1.1 is currently the only implementaion of JAXB?

    2. Are you worried that in the future different JAXB implementations will generate incompatible XML schema binding interfaces and classes and you may have to change your code if you choose another implementation?

    3. Not a lot of people know how to create XML schemas from scratch. What tool do you use to create a schema from an XML file?

    Again, thanks for your insight.
  5. XML from Java Objects[ Go to top ]

    In MHO, go with the deadlines on your project.

    1) If you have lots of time to design and can do extra programming work, use standards like DOM, SAX etc.

    2) If you have less time and can deal with shortcuts like 'JDOM' etc. Use it.

    JAXB seems to be the standard way of doing Java Objects <---> XML But JAXB is evolving.

    My understanding of XML schema were enhanced by the articles on "http://xml.com"