Casey Jordan
Casey Jordan

Reputation: 1254

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

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.

Upvotes: 0

Views: 1169

Answers (1)

ziesemer
ziesemer

Reputation: 28697

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

reader.parse(new InputSource(doc));

Upvotes: 0

Related Questions