Android XML解析随机行为
当我试图解析一个XML文件时,会出现一种奇怪的随机行为。有时它是有效的,但在大多数情况下,我得到:Android XML解析随机行为,android,xml,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> <
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/>
我意识到我的文件中有&个,这是不允许的(应该是&)。将通过替换&重试。有时您的httpcall似乎没有收到XML响应。否,我的文件存储在SD卡上。您如何阅读?发布一些与读取文件相关的代码。似乎发生了一些重叠。没有人知道问题可能是什么?@michaelsmith,请确保您没有尝试两次解析同一输入流。
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???");
}