2011-11-02 25 views
1

我能夠爲有效字符做xml解析,但是當我從我的URL字符串中傳遞無效字符時,沒有找到結果,但是當我通過該web服務時從我的瀏覽器然後結果found.so我認爲問題解析爲無效字符做薩克斯xml解析,所以如何克服這個問題,意味着如何處理無效字符意味着在url http://www.arteonline.mobi/iphone/output.php?st=&ct=&type=Clínicas%20y%20Talleres&neigh=
對於類型屬性我通過類型=Clínicas其中第三個字符不是英文字母,它在西班牙文,所以如何處理這個西班牙文如何處理xml解析無效字符在URL中獲取結果

字符。我的代碼是下面....

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

我在URL替換空間,如果任何通過使用臨時= temp.replaceAll(」 「」 %20" );

,但我不能與西班牙字符買賣類型的屬性在我的Web服務URL .PLS幫助.....

還檢查類型= GALERIAS當從Web服務URL通。在這種6 charaacter無效..

+1

你試過URL.encode使用UTF-8 – ingsaurabh

+0

我寫 在我的.xml文件 – shyam

+0

有你看着使用'UrlQuerySanitizer' http://developer.android.com/reference/android/net/UrlQuerySanitizer.html? – Seph

回答

1

你應該使用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="; 

,如果你有問題的字符編碼解析XML,你可以設置由PA使用的編碼時, RSER:<?XML版本= 「1.0」 編碼= 「UTF-8」>

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

is.setEncoding(「ISO-8859-1」);不工作,它也不給結果.... – shyam

+0

可能是另一種編碼。我仍然不知道你的問題是與呼叫還是解析有關......你是否收到XML到你的SAXHandler中? – Chiara

+0

謝謝你做了我很多幫助我..我會很快發佈我的代碼.... – shyam