framework for marsheling java beans to xml accroding to xml Schema?

E

elh.maayan

hi..

is there a framework, that given a java bean and an xml schema from a
wsdl, would be able to marhsall it correctly according to that schema?
( i need to convert it later to an OMElement of axis)
 
J

JC

hi..

is there a framework, that given a java bean and an xml schema from a
wsdl, would be able to marhsall it correctly according to that schema?
( i need to convert it later to an OMElement of axis)


An XML schema imposes constraints on the contents of an XML document
but does not define a mapping of arbitrary data to that XML. There is
not enough info in an XML schema to map a bean to XML. Some XML
element names may coincidentally have the same names as some of your
bean fields but that is not sufficient information for a mapping.

One option is to use java.beans.XMLEncoder (http://java.sun.com/j2se/
1.4.2/docs/api/java/beans/XMLEncoder.html) to serialize your bean to
XML. I have never used XMLEncoder. AFAIK, your bean will have to mimic
the correct XML schema so that the generated XML conforms to it.

Another option is to use something like XStream (http://
xstream.codehaus.org/, very easy to use) to serialize your object into
XML. XStream will let you define the mappings. Make sure the mappings
from fields -> XML elements that you define conform to your schema,
and you will be good to go. XStream, however, does not operate on bean
fields, it operates directly on member fields (you can define mappings
with annotations).

There may be more appropriate solutions, those are the only two I can
think of, though.

Jason
 
E

elh.maayan

An XML schema imposes constraints on the contents of an XML document
but does not define a mapping of arbitrary data to that XML. There is
not enough info in an XML schema to map a bean to XML. Some XML
element names may coincidentally have the same names as some of your
bean fields but that is not sufficient information for a mapping.

One option is to use java.beans.XMLEncoder (http://java.sun.com/j2se/
1.4.2/docs/api/java/beans/XMLEncoder.html) to serialize your bean to
XML. I have never used XMLEncoder. AFAIK, your bean will have to mimic
the correct XML schema so that the generated XML conforms to it.

Another option is to use something like XStream (http://
xstream.codehaus.org/, very easy to use) to serialize your object into
XML. XStream will let you define the mappings. Make sure the mappings
from fields -> XML elements that you define conform to your schema,
and you will be good to go. XStream, however, does not operate on bean
fields, it operates directly on member fields (you can define mappings
with annotations).

There may be more appropriate solutions, those are the only two I can
think of, though.

Jason

we are allready using XStream, however i need something that will
conform to XSD in wsdl, meaning if i feed a wsdl, it will not that
some attributes should be qualifed with a namespace, and some not, we
allready have classes previosyl generated accroding the schema,but the
tool that generated them (glue) is about to be replaced with axis, so
i'm not afraid about mapping, but with names space issues.
 
A

Arne Vajhøj

is there a framework, that given a java bean and an xml schema from a
wsdl, would be able to marhsall it correctly according to that schema?
( i need to convert it later to an OMElement of axis)

I am relative sure that what you want i JAXB.

With JAXB you can generate a bean from schema and marshal
and unmarshal to and from XML via the generated code.

I can not imagine any tool that will have both bean and
schema as input.

Arne
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top