开发者

XML SAX Android parsing

开发者 https://www.devze.com 2023-03-17 05:37 出处:网络
i want parse xml file, which does\'t have xml extension, like this: http://bizonek.wrzuta.pl/xml/plik/1ANdXCgTOit/unknow/undefined/643/

i want parse xml file, which does't have xml extension, like this: http://bizonek.wrzuta.pl/xml/plik/1ANdXCgTOit/unknow/undefined/643/

my code :

    private DataXml parseLink(String Url) {
    DataXml data = null;

    try {
        URL sourceUrl = new URL(Url);

        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();

        XMLReader xr = sp.getXMLReader();

        XmlParser xmlParser = new XmlParser();
        xr.setContentHandler(xmlParser);

        xr.parse(new InputSource(sourceUrl.openStream()));

        data = xmlParser.getData();

    } catch (ParserConfigurationException pce) {
        Log.e("SAX XML", "sax parse error", pce);
    } catch (SAXException se) {
        Log.e("SAX XML", "sax error", se);
    } catch (IOException ioe) {
        Log.e("SAX XML", "sax parse io error", ioe);
    }
    return data;
}

Logs:

07-05 16:37:52.220: ERROR/SAX XML(538): sax parse io error
07-05 16:37:52.220: ERROR/SAX XML(538): java.net.UnknownHostException: www.bizonek.wrzuta.pl
07-05 16:37:52.220: ERROR/SAX XML(538):     at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
07-05 16:37:52.220: ERROR/SAX XML(538):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
07-05 16:37:52.220: ERROR/SAX XML(538):     at java.net.InetAddress.getAllByName(InetAddress.java:256)
07-05 16:37:52.220: ERROR/SAX XML(538):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
07-05 16:37:52.220: ERROR/SAX XML(538):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
07-05 16:37:52.220: ERROR/SAX XML(538):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
07-05 16:37:52.220: ERROR/SAX XML(538):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
07-05 16:37:52.220: ERROR/SAX XML(538):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
07-0开发者_StackOverflow中文版5 16:37:52.220: ERROR/SAX XML(538):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
07-05 16:37:52.220: ERROR/SAX XML(538):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1018)
07-05 16:37:52.220: ERROR/SAX XML(538):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512)
07-05 16:37:52.220: ERROR/SAX XML(538):     at java.net.URL.openStream(URL.java:645)
07-05 16:37:52.220: ERROR/SAX XML(538):     at beta.wrzuta.dev.Wrzuta.parseLink(Wrzuta.java:55)
07-05 16:37:52.220: ERROR/SAX XML(538):     at beta.wrzuta.dev.Wrzuta.onCreate(Wrzuta.java:34)
07-05 16:37:52.220: ERROR/SAX XML(538):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-05 16:37:52.220: ERROR/SAX XML(538):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-05 16:37:52.220: ERROR/SAX XML(538):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-05 16:37:52.220: ERROR/SAX XML(538):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-05 16:37:52.220: ERROR/SAX XML(538):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-05 16:37:52.220: ERROR/SAX XML(538):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 16:37:52.220: ERROR/SAX XML(538):     at android.os.Looper.loop(Looper.java:123)
07-05 16:37:52.220: ERROR/SAX XML(538):     at android.app.ActivityThread.main(ActivityThread.java:3683)
07-05 16:37:52.220: ERROR/SAX XML(538):     at java.lang.reflect.Method.invokeNative(Native Method)
07-05 16:37:52.220: ERROR/SAX XML(538):     at java.lang.reflect.Method.invoke(Method.java:507)
07-05 16:37:52.220: ERROR/SAX XML(538):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-05 16:37:52.220: ERROR/SAX XML(538):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-05 16:37:52.220: ERROR/SAX XML(538):     at dalvik.system.NativeStart.main(Native Method)


I've seen the UnknownHostException before. In your androidmanifest.xml, check to see if you have given proper internet permissions.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
0

精彩评论

暂无评论...
验证码 换一张
取 消