1

我正在尝试解析托管在我的 Dropbox 文件夹中的 XML 文件。但我似乎无法连接并得到它。这是我正在使用的代码:

try{
    System.out.println("Forst Hit");

    URL hjemmeside = new URL(URLadresse);

    //Henter XMLreader for a parse data

    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    XMLReader xr = sp.getXMLReader();

    System.out.println("Hit");

    HenteData hentedata = new HenteData();
    xr.setContentHandler(hentedata);

    System.out.println("sa Hit");

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

    System.out.println("sa Hit");

    int timeprisdata = hentedata.henteTimespris();
    System.out.println(timeprisdata);

}catch(Exception e){

    e.printStackTrace();

    System.out.println("Noe gikk galt!");

}

这是例外:

11-06 14:31:07.504: W/System.err(487): org.apache.harmony.xml.ExpatParser$ParseException: At line 14, column 50: not well-formed (invalid token)
11-06 14:31:07.504: W/System.err(487):  at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:523)
11-06 14:31:07.504: W/System.err(487):  at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:482)
11-06 14:31:07.504: W/System.err(487):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:320)
11-06 14:31:07.504: W/System.err(487):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:277)
11-06 14:31:07.514: W/System.err(487):  at com.powermedia.delightful.Kalkulator$1.onClick(Kalkulator.java:81)
11-06 14:31:07.514: W/System.err(487):  at android.view.View.performClick(View.java:2408)
11-06 14:31:07.514: W/System.err(487):  at android.view.View$PerformClick.run(View.java:8816)
11-06 14:31:07.514: W/System.err(487):  at android.os.Handler.handleCallback(Handler.java:587)
11-06 14:31:07.514: W/System.err(487):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 14:31:07.514: W/System.err(487):  at android.os.Looper.loop(Looper.java:123)
11-06 14:31:07.514: W/System.err(487):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-06 14:31:07.514: W/System.err(487):  at java.lang.reflect.Method.invokeNative(Native Method)
11-06 14:31:07.514: W/System.err(487):  at java.lang.reflect.Method.invoke(Method.java:521)
11-06 14:31:07.514: W/System.err(487):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-06 14:31:07.514: W/System.err(487):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-06 14:31:07.514: W/System.err(487):  at dalvik.system.NativeStart.main(Native Method)

这是我的 XML 文件:

  <?xml version="1.0" encoding="UTF-8"?>

  <delightful>

    <timepris data = "200"/>

    <marsipanlite data = "100"/>
    <marsipanmiddels data = "150"/>
    <marsipanmye data = "200"/>

    <sjokoladebunn data = "200"/>
    <sukkerbunn data = "150"/>


   </delightful>

我似乎无法弄清楚出了什么问题。有任何想法吗?

4

1 回答 1

1

我发现了问题。我在 Dropbox 上托管了 XML 文件并使用了那里的 URL,但这似乎导致了错误,因为当我在我的私人网络主机上托管相同的 XML 文件时,它一切正常。

于 2013-11-06T17:33:06.340 回答