File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Regarding JAXB 1.3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Regarding JAXB 1.3" Watch "Regarding JAXB 1.3" New topic
Author

Regarding JAXB 1.3

Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Can I use JAXB to convert Java class to xml without using the classes generated by schema compiler.

ie, I manually created the bean classes and i want to convert it to xml using JAXB. Is there any way to do that?


Thanks In Advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42594
    
  65
If the classes follow JavaBeans conventions then you don't need JAXB. Have a look at the java.beans.XMLEncoder/XMLDecoder classes.


Ping & DNS - my free Android networking tools app
Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Will it support Array of Objects.

Lets say

private Students[] student; which contains array of student object.
Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Also it is not preparing xml in a goo format.

The below xml is the one i got for a bean with 2 attributes id and name.

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_04" class="java.beans.XMLDecoder">
<object class="test.mainpgms.A">
<void property="id">
<string>Id</string>
</void>
<void property="name">
<string>Name</string>
</void>
</object>
</java>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42594
    
  65
If the format of the XML matters (why?) you could use an XSLT transformation to transform it into any format you like.

If you're looking for more options, a library like XStream is probably more up your alley.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regarding JAXB 1.3