org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found???
handler如下:
public class getpricelawHandler extends DefaultHandler{ private StringBuilder builder = new StringBuilder();; //private List<String> ktype = null; //任务信息列表 private List<Map<String,String>> lawlist = null; private Map<String,String> map; public List<Map<String,String>> getlawList(){ return lawlist; } @Override public void characters(char[] ch, int start, int length) throws SAXException { super.characters(ch, start, length); builder.append(ch, start, length); } @Override public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { super.startElement(uri, localName, name, attributes); // if(localName.equalsIgnoreCase("ctype")){ // ctype = new ArrayList<String>(); // } if(localName.equalsIgnoreCase("lawlist")){ lawlist = new ArrayList<Map<String,String>>(); } if(localName.equalsIgnoreCase("law")){ map = new HashMap<String,String>(); } } @Override public void startDocument() throws SAXException { super.startDocument(); } @Override public void endElement(String uri, String localName, String name) throws SAXException { super.endElement(uri, localName, name); if(localName.equalsIgnoreCase("code")){ String good = builder.toString(); Log.i("?>>>>>>>>ktype",builder.toString()); // ktype.add(good); } if(localName.equalsIgnoreCase("message")){ String returncode = builder.toString(); Log.i("-->>>>>>>>message",builder.toString()); //ctype.add(returncode); } if(localName.equalsIgnoreCase("law")){ String[] returncode = builder.toString().split(";"); map.put("lawtitle", returncode[0]); Log.i("-->>>>>>>>law0",returncode[0]); Log.i("-->>>>>>>>law1",returncode[1]); lawlist.add(map); //ctype.add(returncode); } builder.setLength(0); } }调用的地方:
SAXParserFactory factory = SAXParserFactory.newInstance(); getpricelawHandler handler = new getpricelawHandler(); SAXParser parser = factory.newSAXParser(); parser.parse(oInputStream, handler);附xml如下:
<?xml version="1.0" encoding="UTF-8"?> <getpricelaw><code>00</code><message>查询成功</message><lawlist><law>中华人民共和国行政许可法;制度法规</law><law>中华人民共和国行政诉讼法;制度法规</law><law>价格行政处罚程序规定;制度法规</law><law>政府制定价格行为规则(试行);制度法规</law><law>禁止价格欺诈行为的规定;制度法规</law><law>中华人民共和国行政处罚法;制度法规</law><law>中华人民共和国价格法;制度法规</law><law>价格监测规定;制度法规</law><law>政府价格决策听证办法;制度法规</law><law>食盐价格管理办法;制度法规</law></lawlist></getpricelaw>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有此问题