xml to object and vice versa

J

JyotiC

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
 
M

mikew01

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
 
J

JyotiC

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

Regards,
Jyoti
 
A

Arne Vajhøj

JyotiC said:
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
 
G

gimme_this_gimme_that

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

JyotiC

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
 
A

Arne Vajhøj

JyotiC said:
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
 
J

JyotiC

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
 
G

gimme_this_gimme_that

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

JyotiC

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.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top