cancel
Showing results for 
Search instead for 
Did you mean: 

Error while parsing a StringReader: Root element is required

Former Member
0 Kudos

Hi

I have a strange issue of with StringReader stream is getting closed. please check the code below

public static GenericDataInstance readGdi(StringReader aReader) {

...

SAXParserFactory lParserFactory = PartialCopyOfXMLServices.getParserFactory();

SAXParser lParser = lParserFactory.newSAXParser();

XMLReader lReader = lParser.getXMLReader(); *<======= "aReader" Stream is getting closed*

// set content handler

....

In the above code whenever the lParser.getXmlReader is called then,

"aReader" object's stream is getting closed.

has any one faced a similar kind of issue?

regards

Rajesh R

Accepted Solutions (0)

Answers (3)

Answers (3)

prasannakrishna_mynam
Contributor
0 Kudos

Hi,

public void parseXML(StringReader aReader) {

DefaultHandler handler = this;

SAXParserFactory factory = SAXParserFactory.newInstance();

SAXParser saxParser = factory.newSAXParser();

XMLReader iread=saxParser.getXMLReader();

}

When i execute this, normally it does nothing, so my output is nothing, i didn't get any errors like aReader is close like that, it works ok for me.

When calling the method, there i initialized aReader to a String like below.

StringReader aReader_call=new StringReader(" XMLString");

try anywhere you missed initializing aReader or closing the object before the call..

Regards..

Krishna..

prasannakrishna_mynam
Contributor
0 Kudos

Hi,

Yes, here we are not using the aReader any where in the method, The SAXParser's Parse method accpets InputStream. For this case, i have tried something of this kind, check the bellow code.

public void parseXMLDoc(StringReader aReader) {

DefaultHandler handler = this;

SAXParserFactory factory = SAXParserFactory.newInstance();

}

prasannakrishna_mynam
Contributor
0 Kudos

Hi Rajesh,

Where are you pasing the StringReader, i don't see any where you are passing the reference of StringReader. if you missed that can you provide detailed code snippet.

Regards.

krishna.

Former Member
0 Kudos

Hi

if you see the parameter being passed to the method

public static GenericDataInstance readGdi(StringReader aReader) {

'aReader is a String reader.

The strange part is, the 'aReader' is not passed to the SAXparser, but still the reader is getting closed.

regards

Rajesh R