xml to object and vice versa

Discussion in 'Java' started by JyotiC, Jul 23, 2008.

  1. JyotiC

    JyotiC Guest

    Hi,

    I have an xml file, corresponding to an xsd. If there some tool, which
    would take this xml and xsd and give me an object. And also take the
    object and xsd and give me xml.

    I read about couple of tools like JAXB, xstrem and xmlBeans.
    The issue i have with them, is they make their own classes, i want to
    use classes which i have already defined by my object. And it's not
    similar to the ones they create.

    Is there any other tool, which also takes classes and use that for
    object?

    Regards,
    Jyoti
     
    JyotiC, Jul 23, 2008
    #1
    1. Advertising

  2. JyotiC

    mikew01 Guest

    On 23 Jul, 12:02, JyotiC <> wrote:
    > Hi,
    >

    http://www.castor.org/

    Mike.



    > I have an xml file, corresponding to an xsd. If there some tool, which
    > would take this xml and xsd and give me an object. And also take the
    > object and xsd and give me xml.
    >
    > I read about couple of tools like JAXB, xstrem and xmlBeans.
    > The issue i have with them, is they make their own classes, i want to
    > use classes which i have already defined by my object. And it's not
    > similar to the ones they create.
    >
    > Is there any other tool, which also takes classes and use that for
    > object?
    >
    > Regards,
    > Jyoti
     
    mikew01, Jul 23, 2008
    #2
    1. Advertising

  3. JyotiC

    JyotiC Guest

    Thanks Mike.
    It's saying about the mapping file.
    Could Castor use xsd instead of a mapping file?

    Regards,
    Jyoti

    On Jul 23, 6:33 pm, mikew01 <> wrote:
    > On 23 Jul, 12:02, JyotiC <> wrote:> Hi,
    >
    > http://www.castor.org/
    >
    > Mike.
    >
    > > I have an xml file, corresponding to an xsd. If there some tool, which
    > > would take this xml and xsd and give me an object. And also take the
    > > object and xsd and give me xml.

    >
    > > I read about couple of tools like JAXB, xstrem and xmlBeans.
    > > The issue i have with them, is they make their own classes, i want to
    > > use classes which i have already defined by my object. And it's not
    > > similar to the ones they create.

    >
    > > Is there any other tool, which also takes classes and use that for
    > > object?

    >
    > > Regards,
    > > Jyoti
     
    JyotiC, Jul 23, 2008
    #3
  4. JyotiC

    Arne Vajhøj Guest

    JyotiC wrote:
    > I have an xml file, corresponding to an xsd. If there some tool, which
    > would take this xml and xsd and give me an object. And also take the
    > object and xsd and give me xml.
    >
    > I read about couple of tools like JAXB, xstrem and xmlBeans.
    > The issue i have with them, is they make their own classes, i want to
    > use classes which i have already defined by my object. And it's not
    > similar to the ones they create.


    I think you should redesign. It is not good to have two
    originals: both xsd and java. One should be generated from
    the other. And then all tools will work.

    Arne
     
    Arne Vajhøj, Jul 24, 2008
    #4
  5. JyotiC

    mikew01 Guest

    > It's saying about the mapping file.
    > Could Castor use xsd instead of a mapping file?


    Not sure on that one Ive only ever used it with the castor mapping
    files, very easy to set up and very versatile, we use it commercially.
    This tutorial seems to make use of an xsd http://www.geocities.com/sireenmalik/details.html.

    Mike.
     
    mikew01, Jul 24, 2008
    #5
  6. JyotiC

    Guest


    > The issue i have with them, is they make their own classes, i want to
    > use classes which i have already defined by my object. And it's not
    > similar to the ones they create.


    Write a XMLRenderer interface and a XMLRenderer class for your class.

    And make your class XMLRenderable and set it up so it can be
    instantiated with a XMLRender.

    It's tedious to write the rendering and instanciating code yourself
    (although there are workarounds) but with some packages - especially
    when you're dealing with XML - you can run into encoding issues - like
    you render an object assuming UTF-8 and it's something else and you
    end up with a null object instead of something usable.

    Later, if you'd like, you can swap out the XMLRender class to use
    Castor or JDOM or reflection, whatever you want.
     
    , Jul 25, 2008
    #6
  7. JyotiC

    JyotiC Guest

    On Jul 24, 6:38 am, Arne Vajhøj <> wrote:
    > JyotiC wrote:
    > > I have an xml file, corresponding to an xsd. If there some tool, which
    > > would take this xml and xsd and give me an object. And also take the
    > > object and xsd and give me xml.

    >
    > > I read about couple of tools like JAXB, xstrem and xmlBeans.
    > > The issue i have with them, is they make their own classes, i want to
    > > use classes which i have already defined by my object. And it's not
    > > similar to the ones they create.

    >
    > I think you should redesign. It is not good to have two
    > originals: both xsd and java. One should be generated from
    > the other. And then all tools will work.
    >
    > Arne


    My java code is generated from xsd. But it's different format then
    JAXB and others. Now i need to add functionality of to and from xml.

    Regards,
    Jyoti
     
    JyotiC, Jul 28, 2008
    #7
  8. JyotiC

    Arne Vajhøj Guest

    JyotiC wrote:
    > On Jul 24, 6:38 am, Arne Vajhøj <> wrote:
    >> JyotiC wrote:
    >>> I have an xml file, corresponding to an xsd. If there some tool, which
    >>> would take this xml and xsd and give me an object. And also take the
    >>> object and xsd and give me xml.
    >>> I read about couple of tools like JAXB, xstrem and xmlBeans.
    >>> The issue i have with them, is they make their own classes, i want to
    >>> use classes which i have already defined by my object. And it's not
    >>> similar to the ones they create.

    >> I think you should redesign. It is not good to have two
    >> originals: both xsd and java. One should be generated from
    >> the other. And then all tools will work.

    >
    > My java code is generated from xsd. But it's different format then
    > JAXB and others. Now i need to add functionality of to and from xml.


    You should obviously have picked a tool that generated Java code
    that had read and write capability.

    But if you did not and you can not switch tool, then I think you
    will need to write code yourself.

    Arne
     
    Arne Vajhøj, Jul 28, 2008
    #8
  9. JyotiC

    JyotiC Guest

    On Jul 25, 5:58 am, ""
    <> wrote:
    > > The issue i have with them, is they make their own classes, i want to
    > > use classes which i have already defined by my object. And it's not
    > > similar to the ones they create.

    >
    > Write a XMLRenderer interface and a XMLRenderer class for your class.
    >
    > And make your class XMLRenderable and set it up so it can be
    > instantiated with a XMLRender.
    >
    > It's tedious to write the rendering and instanciating code yourself
    > (although there are workarounds) but with some packages - especially
    > when you're dealing with XML - you can run into encoding issues - like
    > you render an object assuming UTF-8 and it's something else and you
    > end up with a null object instead of something usable.
    >
    > Later, if you'd like, you can swap out the XMLRender class to use
    > Castor or JDOM or reflection, whatever you want.


    This sounds good. I'd give it a try. Thanks!
    I do have one question in it. If my xsd use sequence. How would
    XMLRenderer know about order?

    Regards,
    Jyoti
     
    JyotiC, Jul 28, 2008
    #9
  10. JyotiC

    Guest

    If you're looking for something that knows about sequences I recommend
    that you lookup up hibernate and middle-gen.

    middle-gen can connect to a database and:

    Create XML representations of the tables
    Handle sequences for most databases - MySQL, Oracle, and DB2
    Can create Java classes from the database-tables/XML-representations
    with getters and setters
    Provides a tool to tweak datatypes such as Longs instead of Integers
    The same tool also creates an ERD of the database tables.



    > I do have one question in it. If my xsd use sequence. How would
    > XMLRenderer know about order?
    >
    > Regards,
    > Jyoti- Hide quoted text -
    >
    > - Show quoted text -
     
    , Jul 28, 2008
    #10
  11. JyotiC

    JyotiC Guest

    On Jul 29, 12:47 am, ""
    <> wrote:
    > If you're looking for something that knows about sequences I recommend
    > that you lookup up hibernate and middle-gen.
    >
    > middle-gen can connect to a database and:
    >
    > Create XML representations of the tables
    > Handle sequences for most databases - MySQL, Oracle, and DB2
    > Can create Java classes from the database-tables/XML-representations
    > with getters and setters
    > Provides a tool to tweak datatypes such as Longs instead of Integers
    > The same tool also creates an ERD of the database tables.
    >
    > > I do have one question in it. If my xsd use sequence. How would
    > > XMLRenderer know about order?

    >
    > > Regards,
    > > Jyoti- Hide quoted text -

    >
    > > - Show quoted text -


    Sorry for not being clear. I meant if i have something like this in my
    xsd:

    <xs:complexType name="Temp">
    <xs:sequence>
    <xs:element name="A" type="xs:string"/>
    <xs:element name="B" type="xs:boolean"/>
    </xs:seqeunce>
    </xs:complexType>

    How would XMlRenderer handle this? When the output XML is generated,
    does it make sure that A tag is before B.

    Regards,
    Jyoti
     
    JyotiC, Jul 30, 2008
    #11
    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. Sam Hwang

    Java Object to XML and vice versa

    Sam Hwang, Apr 24, 2005, in forum: Java
    Replies:
    5
    Views:
    1,019
    iksrazal
    Apr 25, 2005
  2. Zunbeltz Izaola

    from data structure to xml an vice versa

    Zunbeltz Izaola, Dec 12, 2003, in forum: XML
    Replies:
    0
    Views:
    396
    Zunbeltz Izaola
    Dec 12, 2003
  3. Matt Garman
    Replies:
    1
    Views:
    672
    Matt Garman
    Apr 25, 2004
  4. Tamer Higazi
    Replies:
    1
    Views:
    179
    Steven D'Aprano
    Jan 22, 2012
  5. System Administrator

    Function instanceof Object and vice-versa ?

    System Administrator, Mar 10, 2007, in forum: Javascript
    Replies:
    2
    Views:
    145
Loading...

Share This Page