public class TestParser {
//Vars to save the info
private String text;
private String number;
private MyParser myparser;
public void fetchInfo(String urls) {
try {
URL url = new URL(urls);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
myparser = new MyParser();
xr.setContentHandler(myparser);
Log.i("ExampleParse", "Parsing starting");
xr.parse(new InputSource(url.openStream()));
Log.i("ExampleParse", "Parsing done");
//Get parsed info
text=myparser.getText();
number=myparser.getNumber();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Be the first to comment