sarah
sarah

Reputation: 2397

Problem in using stream reader

I have XML data as a string which has to parsed, I am converting the XML string to inputsource using the following code:

StringReader reader1 = new StringReader( xmlstring);
InputSource inputSource1= new InputSource( reader );

And I am passing input source to

Document doc = builder.build(inputSource);

I want to use the same inputSource1 in another parser class also, but I am getting stream closed.

How would I handle this or is there any other way to pass XML data to a parser other than file?

Upvotes: 0

Views: 342

Answers (1)

Thilo
Thilo

Reputation: 262534

Looking at the JavaDoc, it seems that InputSource is not designed to be shared and reused by multiple parsers.

standard processing of both byte and character streams is to close them on as part of end-of-parse cleanup, so applications should not attempt to re-use such streams after they have been handed to a parser.

So you will have to create a new InputSource. If you are really reading from a String, there would be no difference in I/O or memory cost anyway.

Upvotes: 3

Related Questions