0

I have developed simple webservice base math app in which I use the XML base service and use sax parser to parse the webservice response.

I already parse the XML base webservice using sax parser but my problem is when I parse this not get the whole data of the particular tag. For this my code is below.

private List < Object > callWebService() {
 try {
  SAXParserFactory factory = SAXParserFactory.newInstance();
  SAXParser parser = factory.newSAXParser();

  final List < Object > list = new ArrayList < Object > ();

  DefaultHandler handler = new DefaultHandler() {
   boolean language = false;
   boolean langid = false;
   boolean langname = false;
   boolean icon = false;

   public void startDocument() throws SAXException {
    list.clear();
   }

   public void endDocument() throws SAXException {}

   public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    if (qName.equalsIgnoreCase("language")) {
     language = true;
     objLanguage = new Language();
     return;
    }

    if (qName.equalsIgnoreCase("langid")) {
     langid = true;
     return;
    }

    if (qName.equalsIgnoreCase("langname")) {
     langname = true;
     return;
    }
    if (qName.equalsIgnoreCase("icon")) {
     icon = true;
     return;
    }
   }

   public void endElement(String uri, String localName, String qName) throws SAXException {
    if (qName.equalsIgnoreCase("langid")) {
     langid = false;
     return;
    }

    if (qName.equalsIgnoreCase("langname")) {
     langname = false;
     return;
    }
    if (qName.equalsIgnoreCase("icon")) {
     icon = false;
     return;
    }

    if (qName.equalsIgnoreCase("language")) {
     if (langid == false && langname == false && icon == false) {
      language = false;
      list.add(objLanguage);
      return;
     }
    }
   }

   public void characters(char ch[], int start, int length) throws SAXException {
    String theString = new String(ch, start, length);

    if (langid == true) {
     objLanguage.setLangId(theString);
    } else if (langname == true) {
     objLanguage.setLangName(theString);
    } else if (icon == true) {
     objLanguage.setIconImage(genHelper.convertIconImageInByteBuffer(theString));
    }
   }
  };

  parser.parse("http://mathevaluate.com/webservice/langlist.php", handler);
  return list;
 } catch (Exception ex) {
  System.out.println("ERROR : " + ex.toString());
  return null;
 }
}

Problem is language Name Tag which contain very big string of data like

<langname>this is the part where  i can`t get the whole string of the tag so post this question</langname>

When I parse this it can`t get the proper string value of this tag how can I get this?

BK19
  • 1,514
  • 3
  • 22
  • 33
Zala Janaksinh
  • 2,929
  • 5
  • 32
  • 58

1 Answers1

0

If you special characters such as apostrophes and others in your response the data will break at that particular point. You can read here for more SAX parser: Ignoring special characters

Community
  • 1
  • 1
Dinesh Venkata
  • 1,087
  • 1
  • 9
  • 22