public void read ( InputStream is , String encoding , final TagListener listener ) { mSaxHandler . initialize ( ) ; Reader reader = null ; try { reader = new InputStreamReader ( is , encoding ) ; SAXParserFactory spf = SAXParserFactory . newInstance ( ) ; // To correspond to a big entities spf . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , false ) ; XMLReader xmlReader ; xmlReader = spf . newSAXParser ( ) . getXMLReader ( ) ; mSaxHandler . setTagEventListener ( new TagEventListener ( ) { @ Override public void onTagStarted ( String fullTagName , String tagName ) { if ( listener != null ) { listener . onTagStarted ( BigXmlReader . this , fullTagName , tagName ) ; } } @ Override public void onTagFinished ( String fullTagName , String tagName , String value , Attributes atts ) { if ( listener != null ) { listener . onTagFinished ( BigXmlReader . this , fullTagName , tagName , value , atts ) ; } } } ) ; xmlReader . setContentHandler ( mSaxHandler ) ; InputSource iso = new InputSource ( reader ) ; xmlReader . parse ( iso ) ; } catch ( BasicSAXHandlerException e ) { // Force stopped } catch ( ParserConfigurationException e ) { e . printStackTrace ( ) ; } catch ( SAXException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } }
Read big XML file from specific stream