How do I unmarshal to only a portion of generated JAXB classes?
843834May 3 2004 — edited May 5 2004I have an XML schema that is laid out something like this:
<Information>
<Header/>
<Item> (Unbounded)
<Trailer/>
</Information>
I receive files that have thousands of items in them. Because of the size of the files, I must use SAX to parse the file.
I need to unmarshal each file and store the results in a database after following some conditional logic. It is not practical to unmarshal a 500 MB file.
What I have been doing is using a SAX DefaultHandler to strip out each <Item> element.
I had to create a separate schema for just the <Item> element so that I could use JAXB's xjc to generate a set of classes to unmarshal each <Item> element to.
This works great, but it is a hassle to maintain. You see, I also need to unmarshal the <Header> element. So I have to create a separate schema for that as well. So then I end up with two sets of JAXB classes, with lots of duplication. Plus, if I have any complex types that are referenced in both the <Header> and the <Item>, then I have to include those in each sub schema.
What I want to know is:
Is it possible to just generate ONE set of JAXB classes for the main schema, and then unmarshal the stripped out <Item> element to just the corresponding Item in the generated JAXB classes?
This is a complicated topic, and I hope I've been clear. Basically, I have to create these <Header> and <Item> schemas by hand every time the main schema changes, and I want to get away from that.