xml - JAXB : unmarshalexception - with linked exception: [java.io.IOException: Stream closed] -
i trying parse xml using sax ,i want use jaxb build map element name , value.i want override startelement , endelemnt have reached here until far , getting unmarshal exception.any appreciated!.
jaxbcontext jaxbcontext = jaxbcontext.newinstance(my.class);
unmarshaller jaxbunmarshaller = jaxbcontext.createunmarshaller(); unmarshallerhandler unmarshallerhandler = jaxbunmarshaller.getunmarshallerhandler(); saxparserfactory spf = saxparserfactory.newinstance(); saxparser sp = spf.newsaxparser(); xmlreader xr = sp.getxmlreader(); xr.setcontenthandler(unmarshallerhandler); inputstream inputstream = this.getclass().getresourceasstream("my.xml"); inputsource inputsource = new inputsource(inputstream); xr.parse(inputsource); jaxbelement element = (jaxbelement) jaxbunmarshaller.unmarshal(inputsource); //or if unmarahall specific class object still same exception. } catch (jaxbexception e) { // exception occured e.printstacktrace(); }
you can't unmarshal inputsource
after have used sax parse on it. object call getresult
on unmarshallerhandler
.
Comments
Post a Comment