URL oUrl = new URL(sUrl);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
MyXMLHandler handler = new MyXMLHandler();
xr.setContentHandler(handler);
xr.parse(new InputSource(oUrl.openStream()));
Syntax Highlighting by Pygmentool
This way, XML is parsed as it comes in, and the application is much faster and smoother. Also, if you don't parse the whole XML this is an even greater improvement, because you can stop parsing when you have enough data (by throwing a SAXException
) and it will even stop loading data, which results in faster load times and less bandwidth usage.
No comments:
Post a Comment