Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

XmlBeans

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys

I am learning XMLBeans which is an open source tool to convert from XML to java beans.

I want to know if using XMLBeans we can convert from Java beans to XML. Is that possible?

Also , say we have an xml file, is it possible to parse that xml using
XMLBeans API?

thanks very much
Jay
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am learning XMLBeans which is an open source tool to convert from XML to java beans.

I want to know if using XMLBeans we can convert from Java beans to XML. Is that possible?


Yes it is. First step is to create a schema file and then compile
it with the scomp tool. This will generate a jar file containing the
java classes that map to the elements in your schema.

The next bit is bit trickier. The generated files do not include the source. So you're going to have to use javap to generate the byte code.
Using this and a bit of trial and error, you can work out how to use
the various classes. This bit is time consuming and a little annoying,
so if anybody out there has a better way of doing this, please post
a note. Once you've figured out how to use the classes, populate them
with data in your application. When you're ready, call the .toString()
method on the root node and this will generate your xml. BINGO !!!


Also , say we have an xml file, is it possible to parse that xml using
XMLBeans API?

Not quite sure with this one. I have'nt looked at this. If you do find out
please post a note.

kind regards,
Mo


[ May 22, 2007: Message edited by: mo sayed ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic