asynchronous http request xml范例

本文介绍了一种使用XML解析器从服务器获取发票数据的方法,并展示了如何将解析后的数据填充到列表视图中。通过分析XML文档中的各个元素,如金额、公司名称、支付日期等,文章提供了一个具体的例子来说明这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

client.post(context, API_URL, httpEntity, CONTENT_TYPE, new AsyncHttpResponseHandler(){
@Override
public void onSuccess(String response) {
ListView entries;
ArrayList<HashMap<String, String>> invoiceList = new ArrayList<HashMap<String, String>>();
XmlParser xmlParser = new XmlParser();
Document doc = xmlParser.getDomElement(response);
NodeList nl = doc.getElementsByTagName("INVOICE");
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element) nl.item(i);
HashMap<String, String> map = new HashMap<String, String>();
map.put("amount", NumFormat.currency(xmlParser.getValue(e, ("TOTAL"))) + xmlParser.getValue(e, "CURRENCY_CODE"));
map.put("company", xmlParser.getValue(e, "CUSTOMER_ID"));
//map.put("company", xmlParser.getValue(e, "INVOICE_ID"));
map.put("payment", xmlParser.getValue(e, "PAID_DATE"));
map.put("due", xmlParser.getValue(e, "DUE_DATE"));
invoiceList.add(map);
}
InvoiceAdapter adapter = new InvoiceAdapter(getApplicationContext(), invoiceList, customFont);
entries = (ListView) findViewById(R.id.list_outgoing_invoices);
entries.setAdapter(adapter);
}

@Override
public void onFailure(Throwable e, String response) {
Hint.showHint(context, getString(R.string.error_receive_data), Hint.LONG);
}
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值