XML解析随机行为

时间:2012-02-15 21:14:13

标签: android xml

当我尝试解析XML文件时,我得到一个奇怪的随机行为。有时它有效,但在大多数情况下我得到:

ExpatParser$ParseException: At line 1, column 0: no element found

我的XML看起来还不错:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<myTaxiControl version="1.0">
<Cache0>
<digits>1</digits>
<area_bigcar_surch/>

等......总共1.5 Mb

注意:我的文件存储在SD卡上!

FileInputStream fileos;
    try {
        File f = new File(Environment.getExternalStorageDirectory()+"/TarifsCache1.txt");
        fileos = new FileInputStream(f);
    } catch (FileNotFoundException e) {
        return null;
    }

...

SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser=null;
    try {
        parser = factory.newSAXParser();
    XMLReader reader=null;
    reader = parser.getXMLReader();
    MySaxHandler handler = new MySaxHandler();
    reader.setContentHandler(handler);
    InputSource input = new InputSource(fileos);
    reader.parse(input);
    handler.close();// last one would be missed
    tarifsfound = handler.tarifsfound;// .tarifsfound;
    } catch (SAXException e) {
        Log.d("TTT","WHY???");
    }

我意识到我有&amp;在我的文件中,这是不允许的(应该是&amp; amp)。将替换&amp;

再试一次

0 个答案:

没有答案