Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

XmlBeans  RSS feed

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!