我想问一下我的代码有什么问题。我想从 html 页面获取结果并将值存储在字符串中或稍后存储在数组中......谢谢
09-05 16:36:41.221: I/test(22697): 计划失败 1org.xml.sax.SAXParseException: attr 值分隔符丢失!(位置:START_TAG @1:166 in java.io.StringReader@4061bc98)09-05 16:36:41.221:I/test(22697):计划失败 1a @1:166 in java.io.StringReader@4061bc98)09 -05 16:36:41.231: W/System.err(22697): 在 org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:151) 09-05 16:36:41.231: W/System .err(22697): 在 com.asiatype.boracay.CurrencyActivity$DownloadData.doInBackground(CurrencyActivity.java:194) 09-05 16:36:41.231: W/System.err(22697): 在 com.asiatype.boracay。 CurrencyActivity$DownloadData.doInBackground(CurrencyActivity.java:1) 09-05 16:36:41.231: W/System.err(22697): 在 android.os.AsyncTask$2.call(AsyncTask.java:185) 09-05 16 :36:41.231:W / System.err(22697):在java.util.concurrent。
String s,link;
String theResult = "";
link="http://www.bsp.gov.ph/statistics/sdds/exchrate.htm";
Document doc;
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(link);
HttpResponse response;
try {
response = client.execute(request);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
str.append(line);
}
in.close();
htmlSource = str.toString();
} catch (ClientProtocolException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(new InputSource(new StringReader(htmlSource)));
XPathExpression xpath = XPathFactory.newInstance()
.newXPath().compile("//div/table/tbody/tr[child::td[contains(text(),\"USD\")]]/td[15]");
htmlResult = (String) xpath.evaluate(doc, XPathConstants.STRING);
} catch (SAXException e1) {
// TODO Auto-generated catch block
Log.i("test", "plan failed 1"+e1);
Log.i("test", "plan failed 1a "+ htmlSource);
Log.i("test", "plan failed 1a "+ htmlResult);
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
Log.i("test", "plan failed 2");
e1.printStackTrace();
} catch (ParserConfigurationException e1) {
// TODO Auto-generated catch block
Log.i("test", "plan failed 3");
e1.printStackTrace();
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
Log.i("test", "plan failed 4");
e.printStackTrace();
}