私のコードの問題は何ですか?HTMLページから結果を取得し、値を文字列または後で配列に保存したい....ありがとう
09-05 16:36:41.221: I/test(22697): 計画に失敗しました 1org.xml.sax.SAXParseException: attr 値の区切り文字がありません! (position: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/システム.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();
}