I have a situation where I am handed a DOM Document and I need to feed that through a process which uses StAX as part of JAXB binding. So I tried the natural thing and tried wrapping the Document as a javax.xml.transform.dom.DOMSource and passing that to javax.xml.stream.XMLInputFactory#createXMLEventReader(javax.xml.transform.Source):
final Document document = ...;
final DOMSource source = new DOMSource( document );
final XMLInputFactory staxFactory = XMLInputFactory.newInstance();
staxFactory.setXMLResolver( LocalXmlResourceResolver.INSTANCE );
final XMLEventReader staxReader = staxFactory().createXMLEventReader( source );
...
With the JDK built-in StAX handling that lead to errors because apparently reading DOMSources is completely unimplemented.
I then tried swapping in Woodstox as the StAX implementation, which also lead to error (NPE in com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXConnector$1.getPublicId).
Has anyone done this successfully? Is there a way to feed a DOM Document into a StAX event reader?
FWIW, the Document is generated. There is no real XML Document backing it. So I cannot just feed it the XML.