There are many examples of streaming XML through XSLT and then JAXB to Java objects. Often they look like this:
Transformer responseTransformer = TransformerFactory.newInstance().newTransformer(new StreamSource(getClass().getResourceAsStream("ResponseTransformation.xsl"))); Unmarshaller jaxbUnmarshaller = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName()).createUnmarshaller(); JAXBResult jaxbResult = new JAXBResult(jaxbUnmarshaller); responseTransformer.transform(new StreamSource(new StringReader(responseXml)), jaxbResult); res = jaxbResult.getResult();
There are also examples of Unmarshal JAXB from a declared type like this (from Unmarshaller javadoc):
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" ); Unmarshaller u = jc.createUnmarshaller(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new File( "nosferatu.xml")); Element fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a // local element declaration in schema. // FooType is the JAXB mapping of the type of local element declaration foo. JAXBElement<FooType> foo = u.unmarshal(fooSubtree, FooType.class);
Notice how we define FooType.class for the root element in the u.unmarshal(fooSubtree, FooType.class) call u.unmarshal(fooSubtree, FooType.class) . Nice.
Question: Is there a way to combine a streaming processing method, as in the above example, with an indication of the type of declaration, as in the example below?
I like the way to achieve it, but it requires access to the JAXB implementation classes. Of course, this can be done through the open JAXB interface, right?
Thanks!
source share