package com.example.android.apis;import java.util.ArrayList;
import java.util.List;import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;public class RateHandler extends DefaultHandler {
private List<Rate> rates;
private Rate rate;
private String tagName;// 作用是记录解析时的上一个节点名称 public List<Rate> getRates() {
return rates;
} @Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
String data=new String(ch, start, length);
if (tagName.equals("Symbol")) {
rate.setSymbol(data);
}
if (tagName.equals("Name")) {
rate.setName(data);
}
if (tagName.equals("mBuyPrice")) {
rate.setmBuyPrice(data);
}
if (tagName.equals("fBuyPrice")) {
rate.setfBuyPrice(data);
}
if (tagName.equals("SellPrice")) {
rate.setSellPrice(data);
}
if(tagName.endsWith("BasePrice")&&data!=null){
rate.setBasePrice(data);
}
}
//public void startDocument() throws SAXException {
// TODO Auto-generated method stub
// rates = new ArrayList<Rate>();
//} @Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
if ("ForexRmbRate".equals(localName)) {
rates.add(rate);
}
} @Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
tagName = localName;
if ("getForexRmbRate".equals(localName)) {
rates = new ArrayList<Rate>();
}
if ("ForexRmbRate".equals(localName)) {
rate = new Rate();
}
}}在解析这个http://webservice.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx/getForexRmbRate xml文件时
为什么解析出来的
都是空的 DEBUG里面看rate里面的数据都是" "什么都没有
何解 大神们求解啊 烦恼了我两天了 看到我吐血了
import java.util.List;import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;public class RateHandler extends DefaultHandler {
private List<Rate> rates;
private Rate rate;
private String tagName;// 作用是记录解析时的上一个节点名称 public List<Rate> getRates() {
return rates;
} @Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
String data=new String(ch, start, length);
if (tagName.equals("Symbol")) {
rate.setSymbol(data);
}
if (tagName.equals("Name")) {
rate.setName(data);
}
if (tagName.equals("mBuyPrice")) {
rate.setmBuyPrice(data);
}
if (tagName.equals("fBuyPrice")) {
rate.setfBuyPrice(data);
}
if (tagName.equals("SellPrice")) {
rate.setSellPrice(data);
}
if(tagName.endsWith("BasePrice")&&data!=null){
rate.setBasePrice(data);
}
}
//public void startDocument() throws SAXException {
// TODO Auto-generated method stub
// rates = new ArrayList<Rate>();
//} @Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
if ("ForexRmbRate".equals(localName)) {
rates.add(rate);
}
} @Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
tagName = localName;
if ("getForexRmbRate".equals(localName)) {
rates = new ArrayList<Rate>();
}
if ("ForexRmbRate".equals(localName)) {
rate = new Rate();
}
}}在解析这个http://webservice.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx/getForexRmbRate xml文件时
为什么解析出来的
都是空的 DEBUG里面看rate里面的数据都是" "什么都没有
何解 大神们求解啊 烦恼了我两天了 看到我吐血了
解决方案 »
- android程序间函数调用
- android notification
- android 模拟器 sd卡
- opencore中AtomUtils::peekNextByte函数为什么读取的不是下一个字节的值?
- webview加载页面有重叠
- 豌豆荚设置Android铃声的原理是什么?
- 谁能简单的介绍下适配器的工作原理?
- 新手求指导!如何从webservice取出记录,显示在客户端的listview中?
- 【求助】使用intent-filter跳转activity出错
- 冰天雪地裸替跪求 android添加系统级库
- 想在TabHost下嵌套一个listview该怎么做
- android的sqllite能自定义函数吗?
原来是网上 书上的例子都是错的 正确的 解析方法
http://blog.csdn.net/feng88724/article/details/7013675