2011-04-05 75 views
0

傢伙 繼解析數據是我試圖解析無法爲我得到的expatParser異常

<?xml version="1.0" encoding="UTF-8"?><Categories><category name="Banquet & Marriage Hall" id="1" image=""/><category name="Crematorium, Burial Ground" id="2" image=""/><category name="Educational Institution" id="3" image=""/><category name="Embassies & Consulates" id="4" image=""/><category name="Fire Station" id="5" image=""/><category name="Government Office" id="6" image=""/></Categories> 

繼XML是我使用

public byte parse(){ 

       SAXParserFactory spf = null; 
       SAXParser sp = null; 
       InputStream inputStream = null; 

       try { 
        inputStream = new ByteArrayInputStream(data.getBytes()); 
        spf = SAXParserFactory.newInstance(); 
        if (spf != null) { 
         sp = spf.newSAXParser(); 
         **sp.parse(inputStream, this);** 


        } 
       } 
       /* 
       * Exceptions need to be handled MalformedURLException 
       * ParserConfigurationException IOException SAXException 
       */ 

       catch (Exception e) { 
        System.out.println("Exception: " + e); 
        e.printStackTrace(); 
       } finally { 
        try { 
         if (inputStream != null) 
          inputStream.close(); 
        } catch (Exception e) { 
        } 
       } 

       if (categorieslist != null && categorieslist.size() > 0) { 
       // Log.d("Array List Size",""+tipsList.get(4).getTitle()); 


        return 1; 
       } else { 
        return 0; 
       } 

      } 

     public ArrayList<Categories> getParserCategoriesList(){ 
      return categorieslist; 
     } 

     public void startElement(String uri, String localName, String qName, 
        Attributes attributes) throws SAXException { 

      if(localName.equalsIgnoreCase("Categories")){ 
       if(localName.equalsIgnoreCase("category")){ 
        categories = new Categories(); 
        categorieslist.add(categories); 

        categories.setId(attributes.getValue("id")); 
        Log.d("ID",attributes.getValue("id")); 
        categories.setName(attributes.getValue("name")); 
        Log.d("NAME",attributes.getValue("name")); 
        /*categories.setImage(attributes.getValue("image")); 
        Log.d("image",attributes.getValue("image"));*/ 
       } 
      } 
了我的分析器代碼

sp.parse()是給我expatParser異常的代碼 我在前面的5個XML解析中一直使用相同的邏輯,我沒有得到這個錯誤。 我在做什麼錯誤或是它的XML的XML是錯誤的?

+0

請問這個線意味着: - 04-05 13:15:18.057:WARN/System.err(3118):org.apache.harmony.xml.ExpatParser $ ParseException:在第1行,第75列:格式不正確(無效令牌) – abhishek 2011-04-05 08:33:21

回答

0

我認爲解析器在達到&符(&)字符時拋出異常。你可以發現類似於你的問題here

+0

是的dat是現在我正在取代與「和」的事情,它正在工作 – abhishek 2011-04-05 11:51:43

0

是以前的評論是正確的,當解析器到達&或任何特殊字符時,拋出異常,有兩個選項。

  1. 您需要更換特殊字符(使用編碼值)
  2. 你需要用CDATA包含特殊字符的節點綁定..

所有最好的

相關問題