How to set StreamSource.setReader() with custom EntityResolver in XMLReader

1.1k views Asked by At

I need to get a StreamSource from my xml file, however I also need to use a custom EntityResolver.

The problem I am having is that I cannot figurout how to get an XMLReader into my stream source.

I am doing the following: (doc is an InputStream)

XMLReader reader = XMLReaderFactory.createXMLReader();
StreamSource doc_source = new StreamSource(doc);
reader.setEntityResolver(new PsudoEntityResolver());
doc_source.setReader(reader);

Obviously this does not work because setReader() accepts a Reader as its argument and not an XMLReader.

Any ideas how I can get around this.

1

There are 1 answers

2
ziesemer On

Use your XMLReader, set the entity resolver as you are, but then call:

reader.parse(new InputSource(doc));