Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   xml to object and vice versa (http://www.velocityreviews.com/forums/t627168-xml-to-object-and-vice-versa.html)

JyotiC 07-23-2008 11:02 AM

xml to object and vice versa
 
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

mikew01 07-23-2008 01:33 PM

Re: xml to object and vice versa
 
On 23 Jul, 12:02, JyotiC <jyoti.chha...@gmail.com> 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 07-23-2008 02:47 PM

Re: xml to object and vice versa
 
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 <mike...@blueyonder.co.uk> wrote:
> On 23 Jul, 12:02, JyotiC <jyoti.chha...@gmail.com> 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



Arne Vajhøj 07-24-2008 01:38 AM

Re: xml to object and vice versa
 
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

mikew01 07-24-2008 01:05 PM

Re: xml to object and vice versa
 
> 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.

gimme_this_gimme_that@yahoo.com 07-25-2008 12:58 AM

Re: xml to object and vice versa
 

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


JyotiC 07-28-2008 02:42 AM

Re: xml to object and vice versa
 
On Jul 24, 6:38 am, Arne Vajhøj <a...@vajhoej.dk> 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

Arne Vajhøj 07-28-2008 02:47 AM

Re: xml to object and vice versa
 
JyotiC wrote:
> On Jul 24, 6:38 am, Arne Vajhøj <a...@vajhoej.dk> 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

JyotiC 07-28-2008 03:12 AM

Re: xml to object and vice versa
 
On Jul 25, 5:58 am, "gimme_this_gimme_t...@yahoo.com"
<gimme_this_gimme_t...@yahoo.com> 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

gimme_this_gimme_that@yahoo.com 07-28-2008 07:47 PM

Re: xml to object and vice versa
 
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 -




All times are GMT. The time now is 04:42 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57