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