SAXParser的例外Android中 [英] Saxparser exception in Android

查看:114
本文介绍了SAXParser的例外Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我解析从这个数据<一个href=\"http://maps.travelsouthyorkshire.com/iGNMSearchService.asmx/TextSearch?text=West%20bar&maxResults=100\"相对=nofollow> XML网址文本输入而异,这取决于用户。每当有文本的变量空间我得到这个异​​常:

  org.apache.harmony.xml.ExpatParser $ ParseException的:在第11行,第2列:标签不匹配
 org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:520)
 org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
 org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
 org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
 gps.app.tkartor.XMLObjects.XMLParser.findStreet(XMLParser.java:99)

如果没有空格它工作正常。解析code:

 公共无效findStreet(字符串搜索内容){
    尝试{
        URL =新的URL(
                http://maps.travelsouthyorkshire.com/iGNMSearchService.asmx/TextSearch?text=
                        +搜索内容+&放大器;的maxResults = 100);
        的System.out.println(url.toString());
        parserFactory = SAXParserFactory.newInstance();
        解析器= parserFactory.newSAXParser();
        读者= parser.getXMLReader();
        streetHandler =新StreetHandler();
        reader.setContentHandler(streetHandler);
        reader.parse(新的InputSource(url.openStream())); //线99
        POI = streetHandler.getAllStreets();    }赶上(例外五){
        e.printStackTrace();
    }
}


解决方案

指示用空格+

<一个href=\"http://maps.travelsouthyorkshire.com/iGNMSearchService.asmx/TextSearch?text=West+bar&maxResults=100\" rel=\"nofollow\">http://maps.travelsouthyorkshire.com/iGNMSearchService.asmx/TextSearch?text=West+bar&maxResults=100

所以你的情况,你必须更换字符串搜索内容的空间。类似

 搜索内容= searchWord.replace(,+);

I am parsing data from this XML url The text input varies, depending on the user. Whenever there are spaces in the text variable I get this exception:

 org.apache.harmony.xml.ExpatParser$ParseException: At line 11, column 2: mismatched tag
 org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:520)
 org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
 org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
 org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
 gps.app.tkartor.XMLObjects.XMLParser.findStreet(XMLParser.java:99)

If there are no spaces it works fine. Parsing code:

public void findStreet(String searchWord) {
    try {
        url = new URL(
                "http://maps.travelsouthyorkshire.com/iGNMSearchService.asmx/TextSearch?text="
                        + searchWord + "&maxResults=100");
        System.out.println(url.toString());
        parserFactory = SAXParserFactory.newInstance();
        parser = parserFactory.newSAXParser();
        reader = parser.getXMLReader();
        streetHandler = new StreetHandler();
        reader.setContentHandler(streetHandler);
        reader.parse(new InputSource(url.openStream()));//line 99
        poi = streetHandler.getAllStreets();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

解决方案

Indicate spaces with '+'

http://maps.travelsouthyorkshire.com/iGNMSearchService.asmx/TextSearch?text=West+bar&maxResults=100

So in your case you have to replace the spaces of your String "searchWord". Something like

 searchWord = searchWord.replace(" ", "+");

这篇关于SAXParser的例外Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆