try { URL url = new URL(myFeed); // Create a new HTTP URL connection URLConnection connection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection)connection; int responseCode = httpConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { InputStream in = httpConnection.getInputStream(); processStream(in); } } catch (MalformedURLException e) { Log.d(TAG, "Malformed URL Exception.", e); } catch (IOException e) { Log.d(TAG, "IO Exception.", e); }
HttpURLConnection httpConnection = (HttpURLConnection) connection; int responseCode = httpConnection.getResponseCode(); if (responseCode == httpConnection.HTTP_OK) { InputStream in = httpConnection.getInputStream(); DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); // 分析input Document dom = db.parse(in); Element docEle = dom.getDocumentElement(); }
SAXParserFactory factory=SAXParserFactory.newInstance(); SAXParser parser=factory.newSAXParser(); MyHandel handel=new MyHandel (); //此处MyHandle继承自DefaultHandel parser.parse(inputStream, handel);
We recommend XmlPullParser
,
which is an efficient and maintainable way to parse XML on Android.
Historically Android has had two implementations of this interface:
KXmlParser
via
XmlPullParserFactory.newPullParser()
.
ExpatPullParser
, via Xml.newPullParser()
.
factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser();
【Android】PA4D_CH6 使用Internat资源,布布扣,bubuko.com
【Android】PA4D_CH6 使用Internat资源
原文:http://www.cnblogs.com/driftsky/p/3726623.html