0

guys Following is the xml which i am trying to parse

<?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>

Following is the code of my parser which i am using

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() is the code which is giving me the expatParser Exception I have been using the same logic in previous 5 xml parsing and i dont get this error. What am i doing wrong or is it dat the xml is wrong ??

skaffman
  • 398,947
  • 96
  • 818
  • 769
abhishek
  • 1,434
  • 7
  • 39
  • 71
  • what does this line means :- 04-05 13:15:18.057: WARN/System.err(3118): org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 75: not well-formed (invalid token) – abhishek Apr 05 '11 at 08:33

2 Answers2

0

yes previous comment is right, parser is throwing the exception when it reaches & or any special character, two options are there.

  1. you need to replace the special character(use encoded value)
  2. you need to bind the node with CDATA which contains special character..

all the best

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Shyji
  • 11
  • 4
0

I think the parser is throwing the exception when it reaches the ampersand (&) character. You can find a problem similar to yours here

Community
  • 1
  • 1
Twobard
  • 2,553
  • 1
  • 24
  • 27