A Techno Blog, mainly about Java


JAXB is now available as part of the Java Web Services developer pack from Sun. While JAXB was in Beta, you could download Sun’s implemementation of JAXB seperately . It appears that is not the case anymore. Here is my page on sun. I have posted some messages to the various Sun forums on the problem I am having using JAXB. Here is an article on user feedback with JAXB. I may look into other JAXB implementations. Specifically, Apache’s open source JAXME2. Another one is XMLBeans.

I chose JAXME.

JAXME Manual
Featured article on JAXME

How to download: go to jaxme download page and scroll to bottom for distributions (src or bin).

I grabbed the two example files (build.xml and xsd file) from the article and placed them inside the new jaxme directory that was just created when the binaries tar file was extracted.

Edit the build file to set where the jar files are located (lib).
Invoke ‘ant generate’ and the neccesary files get generated in the generated folder.
As well as generating the source code, its creates two files (configuartion.xml and

XML file (schema instance):

< ?xml version=”1.0″ encoding=”UTF-8″? >
<stu:Student xmlns:stu=”;
xmlns:xsi=”; >
<stu:firstName>stu:firstName</stu:firstName >
<stu:lastName>stu:lastName</stu:lastName >
<stu:name>stu:name</stu:name >
<stu:street>stu:street</stu:street >
<stu:city>stu:city</stu:city >
<stu:state>stu:state</stu:state >
</stu:address >

Read XML:


import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.xml.sax.InputSource;

public class Main {

public static Student getAddress(InputSource pSource)
throws JAXBException {
JAXBContext context =
Unmarshaller unmarshaller = context.createUnmarshaller();
return (Student) unmarshaller.unmarshal(pSource);
public static void main(String[] args) throws Exception {
File f = new File(“src/student.xml”);
InputSource isource = new InputSource(new FileInputStream(f));
Student student = getAddress(isource);

August 4, 2004 - Posted by | XML

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: