クラスを使用して Web ページのコンテンツ (xml のようなテキストが含まれています) を読み取り、それを文字列変数に保存しています。正常に動作しています。私が今しなければならないことは、この文字列内のいくつかのタグの値を見つけることです。これは、ページを読み取るクラスです。ご覧のとおり、タグを読み取る必要があるメソッド「onPostExecute」があります。
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient(); //create a new http client
HttpGet httpGet = new HttpGet(url); //create a new http request passing a valid url
try {
HttpResponse execute = client.execute(httpGet); //try to execute the http get request
InputStream content = execute.getEntity().getContent(); //prepare the input stream to read the bytes of the request
BufferedReader buffer = new BufferedReader(
new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s; //until is present a line to read, the response variable store the value of the lines
}
} catch (Exception e) {
Log.i("MyApp", "Download Exception : " + e.toString()); //Print the error if something goes wrong
}
}
Log.i("RESPONSE",""+response);
return response; //return the response
}
@Override
protected void onPostExecute(String result) {
result = webPage.doInBackground(initConfiguration); //take the result from the DownloadWebPageTask class
Log.i("RESULT",""+result);
//find the price and format value from the result
}
}
だから今私は何ができますか?何か提案はありますか?ある種のxmlパーサーを使用する必要がありますか? 1 つまたは 2 つのタグを読み取るだけでよいので、使いやすいものが必要です。タグを含む文字列の例を次に示します。
<products currency="EUR">
<product id="1" width="1796" height="1228" name="10 X 15 cm">
<prices>
<price fixfee="0.5" from="50" price="0.65" />
<price fixfee="0.10" from="20" price="0.70" />
<price fixfee="0.10" from="0" price="0.75" />
</prices>
</product>
<product id="2" width="3626" height="2422" name="20 X 30 cm">
<prices>
<price fixfee="0.5" from="50" price="0.75" />
<price fixfee="0.10" from="20" price="0.80" />
<price fixfee="0.10" from="0" price="0.100" />
</prices>
</product>
ありがとう