如何处理XML解析无效字符使用URL中获取结果 [英] how to deal with xml parsing for invalid character use in URL for getting result

查看:133
本文介绍了如何处理XML解析无效字符使用URL中获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够做的XML解析为有效字符,但是当我从我的URL字符串传递无效字符那么有没有个结果发现,但是当我传递Web服务URL从我的浏览器上,导致被found.so我认为,在分析问题为做SAX解析XML,所以如何从这个问题解决无效字符,这意味着如何处理无效字符的URL的 <一指href=\"http://www.arteonline.mobi/iphone/output.php?st=&ct=&type=Cl%C3%ADnicas%20y%20Talleres&neigh=\" rel=\"nofollow\">http://www.arteonline.mobi/iphone/output.php?st=&ct=&type=Clínicas%20y%20Talleres&neigh=

类型属性我通过类型=Clínicas其中,第三个字符不是一个英文字母,它在西班牙语所以如何处理这个西班牙

i am able to do xml parsing for valid character but when i pass invalid character from my URL string then there no result found but when i pass that web service url from my browser then result is found.so i think problem in parsing for invalid character for doing sax xml parsing ,so how to overcome from this problem ,means how to deal with invalid character means in url http://www.arteonline.mobi/iphone/output.php?st=&ct=&type=Clínicas%20y%20Talleres&neigh=
for type attribute i pass type=Clínicas where 3rd character is not an English alphabet ,its in Spanish so how to deal with this Spanish

字符。我的code是低于....

character. my code is below....

                  @Override
        protected Boolean doInBackground(String... args) {
              try{ 
                  try {



                     String temp = "http://www.arteonline.mobi/iphone/output.php?st="+filter.stateselected+"&ct="+filter.cityselected+"&type="+filter.typeselected+"&neigh="+filter.neighbourselected+"";
                        //String temp = "http://www.arteonline.mobi/iphone/output.php?st=&ct=&type=Clínicas%20y%20Talleres&neigh=";

                      temp = temp.replaceAll(" " ,"%20");
                      //  temp= temp.replaceAll("í" ,"í");
                        SAXParserFactory spf = SAXParserFactory.newInstance();
                        SAXParser sp = spf.newSAXParser();
                        XMLReader xr = sp.getXMLReader();
                        Log.i("temp url..",temp.trim().toString());
                        URL sourceUrl = new URL(temp.trim());
                        XMLHandlerfiltersearch myXMLHandler = new XMLHandlerfiltersearch();
                        xr.setContentHandler(myXMLHandler);
                        xr.parse(new InputSource(sourceUrl.openStream()));

                    } 
                     catch (Exception e) {
                     System.out.println("XML Pasing Excpetion = " + e);
                    }

我在网址替换空间,如果任何通过使用临时= temp.replaceAll(,%20);

i replace space in my url if any by using temp = temp.replaceAll(" " ,"%20");

但在我的Web服务URL .PLS的帮助,我不可能与西班牙字符处理类型属性.....

but i could not deal with Spanish character in type attribute in my web service url .pls help.....

也检查类型= GALERIAS 当来自Web服务URL通..在这6 charaacter是无效的。

also check for type=Galerías when pass from web service url.. in this 6th charaacter is not valid..

推荐答案

您应该使用的 URLEn codeR

String stateselected= URLEncoder.encode(filter.stateselected, "UTF-8");
String cityselected = URLEncoder.encode(filter.cityselected, "UTF-8");
String typeselected= URLEncoder.encode(filter.typeselected, "UTF-8");
String neighbourselected= URLEncoder.encode(filter.neighbourselected, "UTF-8");
String temp = "http://www.arteonline.mobi/iphone/output.php?st="+stateselected+"&ct="+cityselected+"&type="+typeselected+"&neigh="+neighbourselected+"";
//String temp = "http://www.arteonline.mobi/iphone/output.php?st=&ct=&type=Clínicas%20y%20Talleres&neigh=";

如果您在解析时有字符编码的问题,你可以设置解析器使用的编码中的XML:

if you have problems with the character encoding when parsing the XML you could set the encoding used by the parser:

InputSource is = new InputSource(sourceUrl.openStream());
is.setEncoding("ISO-8859-1");
xr.parse(is);

这篇关于如何处理XML解析无效字符使用URL中获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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