users@jaxb.java.net

Re: Converting XML to Java Objects...possible?

From: Gregory Kick <gk5885_at_gmail.com>
Date: Wed, 11 Apr 2007 20:25:58 +0530

I think that there's a bit of confusion about what you want to do.
When you say "XML," I take that to mean a single, generic xml document
(not a schema). If the structure of your document is described by a
schema then jaxb would be the appropriate tool, but if it's not (which
I suspect from your question), then it's not going to work out so
well.

The reason is that, just like raymond said, there's a relationship
between classes and instances. In order to have an object, it must be
the instance of some class. The class describes the structure of the
object. A similar relationship exists between schema documents and
xml documents. The schema document describes the structure of an xml
document. So, what jaxb does for you is take the structure from the
schema and create a corresponding structure in java as a collection of
classes (and vice versa). From there, you can take the instances of
your xml documents and turn them into instances of your java classes.

If you specifically don't want those classes or don't have a schema,
you're going to be stuck with a generic representation of your
document (e.g. DOM).

On 4/11/07, tweety123 <therhythmic_at_yahoo.com> wrote:
>
> Hi all, Thanks for your replies.
>
> How do I actually convert XML to Java object (not class)? I know that to
> convert XML to java classes (not objects), I need to use
> Marshaller.unmarshal(). How do I convert the XML to java "object" (& not
> "class")?
>
> Thanks.
>
>
>
> Malachi de Ælfweald wrote:
> >
> > Or more simply put, JAXB autogenerates an API that reads/writes the XML
> > for
> > you (based on your XSD).
> >
> > :)
> >
> > Malachi
> >
> > On 4/9/07, Prashant <prashant_at_pramati.com> wrote:
> >>
> >> Yes, this is possible with Jaxb and is the primary objective of this
> >> specification.
> >>
> >> JAXB generates the Java Classes from a XSD document.
> >>
> >> Then you can "marshall" any XML instance document of this schema to a
> >> Java Objects.
> >>
> >> If you think of XSD Schema document as a "blue print" Jaxb will generate
> >> Class files (Blue print in Java), then for any incoming XML instance
> >> document (data) JAXB can create Java Object instances.
> >>
> >> Perhaps this will help : http://www.jcp.org/en/jsr/detail?id=31
> >>
> >> *2.1* Please describe the proposed Specification:
> >> The proposed specification will define an /XML data-binding facility/
> >> for the Java^TM Platform. Such a facility compiles an XML schema into
> >> one or more Java classes. These automatically-generated classes handle
> >> the translation between XML documents that follow the schema and
> >> interrelated instances of the derived classes. They also ensure that the
> >> constraints expressed in the schema are maintained as instances of the
> >> classes are manipulated.
> >>
> >> -Prashant
> >>
> >> tweety123 wrote:
> >> > Hi, As far as I know about JAXB, it provides the facility to convert
> >> "XSD"
> >> > (not XML) to Java "classes" (not objects). This can be done using xjc
> >> > compiler. Can XML files (i.e. ones with data) be converted to Java
> >> objects
> >> > (retaining the data from XML files)? If yes, please throw some light on
> >> how
> >> > it can be done. If no, then is there some java technology to do such a
> >> > thing?
> >> >
> >> > Thanks.
> >> >
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> >> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> >>
> >>
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Converting-XML-to-Java-Objects...possible--tf3551108.html#a9940466
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Gregory Kick
http://kickstyle.net/