0

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.

Casey Jordan
  • 1,204
  • 1
  • 20
  • 39

1 Answers1

0

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

reader.parse(new InputSource(doc));
ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • Thanks for the quick reply, although I don't see how this helps me get the reader into my StreamSource. I am constructing the StreamSource to be passed to another method which is doing the parsing (Which I cannot modify). Thanks! – Casey Jordan Dec 08 '11 at 13:13
  • Then sorry, I believe you're stuck. StreamSource only indicates a source of the XML data - a File, byte stream (InputStream), character stream (Reader), or URL. It doesn't contain any additional configurations, e.g. an entity resolver. Even if you subclassed StreamSource to have it contain these configurations, the method being called wouldn't know anything about them and wouldn't use them. – ziesemer Dec 08 '11 at 13:17