Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > xml to object and vice versa

Reply
Thread Tools

xml to object and vice versa

 
 
JyotiC
Guest
Posts: n/a
 
      07-23-2008
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
 
Reply With Quote
 
 
 
 
mikew01
Guest
Posts: n/a
 
      07-23-2008
On 23 Jul, 12:02, JyotiC <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
JyotiC
Guest
Posts: n/a
 
      07-23-2008
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 <(E-Mail Removed)> wrote:
> On 23 Jul, 12:02, JyotiC <(E-Mail Removed)> 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


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      07-24-2008
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
 
Reply With Quote
 
mikew01
Guest
Posts: n/a
 
      07-24-2008
> 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.
 
Reply With Quote
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      07-25-2008

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

 
Reply With Quote
 
JyotiC
Guest
Posts: n/a
 
      07-28-2008
On Jul 24, 6:38 am, Arne Vajh°j <(E-Mail Removed)> 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
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      07-28-2008
JyotiC wrote:
> On Jul 24, 6:38 am, Arne Vajh°j <(E-Mail Removed)> 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
 
Reply With Quote
 
JyotiC
Guest
Posts: n/a
 
      07-28-2008
On Jul 25, 5:58 am, "(E-Mail Removed)"
<(E-Mail Removed)> 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
 
Reply With Quote
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      07-28-2008
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 -


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
access address from object and vice versa Tamer Higazi Python 1 01-22-2012 05:33 AM
Function instanceof Object and vice-versa ? System Administrator Javascript 2 03-10-2007 11:51 PM
Java Object to XML and vice versa Sam Hwang Java 5 04-25-2005 12:22 PM
map XML union to C union (and vice-versa) Matt Garman XML 1 04-25-2004 12:40 AM
from data structure to xml an vice versa Zunbeltz Izaola XML 0 12-12-2003 02:48 PM



Advertisments