1

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

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);
                    }

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

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

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

shyam
  • 1,276
  • 4
  • 25
  • 51

1 Answers1

1

You should use URLEncoder:

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=";

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);
Chiara
  • 1,867
  • 15
  • 17
  • may be is another encoding. I still don't know if your problem is with the call or with the parsing ... Do you receive the XML into your SAXHandler? – Chiara Nov 03 '11 at 18:36