I use SAX to parse a big xml file which is big and has many many repeated node. And use JAXB to map the parsed and repeated dom nodes to javabeans for persistence.
Here is my code fragment. I use JAXB's partial unmarshalling
example code, it create Unmarshaller object each time a node parsing is started. Can i reuse it for one whole xml parsing or cache it for multiple xml parsing?
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
...
if (namespaceURI.equals("") && localName.equals( “product” )) {
Unmarshaller unmarshaller = null;
try {
//I want to reuse it, not create it in each startElement method
unmarshaller = jaxbContext.createUnmarshaller();
} catch (JAXBException e) {
throw new SAXException(e);
}
...