0

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.

Steve Ebersole
  • 9,339
  • 2
  • 48
  • 46
  • Quick & dirty bypass : print your DOM to String (using a DOMSource, a StreamResult backed by a StringWriter, and a TransformerFactory), and feed this to your StaxFactory... Apart from that : what is your DOM and Stax implementations and versions ? Oracle JDK ? – GPI Mar 13 '15 at 14:25
  • Well I just had an interesting discovery. Apparently the thing producing the DOM is producing XML that does not validate against the schema it should. The problem getting the PublicId is part of error reporting. I disabled jaxp validation and am getting much further. – Steve Ebersole Mar 13 '15 at 14:42

0 Answers0