• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JAX-B - Unmarshalling Vs. Read XML data (ObjectFactory)

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading JAXB, and learned the steps of
Unmarshaling (bind, Create JAXBContext, getUnmarshller, call unmarshal)

I also came to know about reading XML data using
ObjectFactory (bind, Create ObjectFactory, get Collection, ...)

I am not able to understand the difference between Unmarshalling & reading XML data using ObjectFactory,
If I have a choice to use either of way to read XML file using JAXB, why should I prefer one to other?
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I understand the part about unmarshalling, but not the second part about reading XML data. Can you give a code example?
If it is an ObjectFactory that you get after binding and you let it create some object for you, then it will not, in itself, help you to read or write XML.
For that, you need an Unmarshaler or a Marshaler. At least these are the techniques that I have seen so far.
Best wishes!
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/developer/technicalArticles/WebServices/jaxb/

An Alternative: Accessing Data without Unmarshalling: JAXB also allows you to access XML data without having to unmarshal it. One of the classes generated from a schema, ObjectFactory, contains methods to generate objects for each of the schema-derived interfaces and classes. For example, the package generated for the books.xsd schema includes an ObjectFactory class that has methods such as createCollection to create a Collection object, and createBookType to create a BookType object. You can use these methods to create a tree of content objects without doing any unmarshalling. All your program needs is access to the ObjectFactory class that's in the package for the pertinent schema. Then you can use the appropriate methods in the ObjectFactory class to create the objects you need. After you create the objects, you need to provide their content. To do that, you use the set methods in the objects.



As per above para which is from source URL, for reading using JAXB, Unmarshlling is the way but user has option of reading the XML source without Unmarshaling.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
No, there is no XML involved in the process described in the quote. I feel that the formulation is unfortunate.
What it means is that you can create a tree of objects that correspond to some XML data by letting an ObjectFactory create the instances and then insert the data yourself, using the setter methods in the objects.
Best wishes!
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmm...

JAXB also allows you to access XML data without having to unmarshal it.


But you are suggesting that it's not reading the XML data but creating ContentObject based on the XML data & using setter method user is adding data to content.

It's contradicting to me. But since I have good experience with your guidance/suggestions, I would prefer to come back to this topic after spending more time on reading about JWS.

Thanks.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic