Exception when parsing from InputSource 2004-02-12 - By W. Nathaniel Mills, III
In the xerces.jar that ships with WSAD 5.1 (C:\wsad51\eclipse\plugins\org .apache.xerces_4.0.13\xercesImpl.jar (1,176,093 bytes), I've found the parser doesn't appear to handle the end of inputsource correctly, when it is constructed from a String, throwing an exception where the line number is -1. I've coded a workaround, but wondered if this is known and fixed, or if there is a better way to deal with this issue.
public void instantiateFrom(String strXML, ArrayList retList) throws XYZException {
StringReader reader = new StringReader(strXML); InputSource inputSource = new InputSource(reader);
m_List = retList; m_Parser.setContentHandler(this); m_Parser.setErrorHandler(this); try { m_Parser.parse(inputSource); } catch (SAXParseException e) { // handle end of file if (e.getLineNumber() != -1) { throw new XYZException(formatSAXParseException(e), e); } // else expected case due to reaching the end of the string } catch (SAXException e) { throw new XYZException(e.getLocalizedMessage(), e); } catch (IOException e) { throw new XYZException(e.getLocalizedMessage(), e); } }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD> <BODY > <DIV><FONT face="Courier New" size=-1>In the xerces.jar that ships with WSAD 5 .1 (C:\wsad51\eclipse\plugins\org.apache.xerces_4.0.13\xercesImpl.jar (1,176,093 bytes), I've found the parser doesn't appear to handle the end of inputsource correctly, when it is constructed from a String, throwing an exception where the line number is -1. I've coded a workaround, but wondered if this is known and fixed, or if there is a better way to deal with this issue.<BR><BR>public void instantiateFrom(String strXML, ArrayList retList)<BR> throws XYZException {</FONT></DIV> <DIV> </DIV> <DIV><FONT face="Courier New" size=-1> StringReader reader = new StringReader(strXML);<BR> InputSource inputSource = new InputSource(reader);</FONT></DIV> <DIV> </DIV> <DIV><FONT face="Courier New" size=-1> m_List = retList;<BR> m_Parser.setContentHandler(this);<BR> m_Parser.setErrorHandler(this);<BR> try {<BR> m_Parser.parse(inputSource);<BR> } catch (SAXParseException e) {<BR>  ; // handle end of file<BR> if (e.getLineNumber() != -1) {<BR> throw new XYZException(formatSAXParseException(e) , e);<BR> } // else expected case due to reaching the end of the string<BR> } catch (SAXException e) {<BR> throw new XYZException(e.getLocalizedMessage(), e);<BR> } catch (IOException e) {<BR> throw new XYZException(e.getLocalizedMessage(), e);<BR> }<BR>}</FONT></DIV> <DIV> </DIV> <DIV><FONT face="Courier New" size=-1></FONT> </DIV></BODY></HTML>
|
|