json - Cannot figure out reason for JDOMException SAXBuilder -


i not able figure out reason jdomexception being caught. passing xml format string saxbulider's build function getting document, exception thrown here.

xml string stored in string results:

<?xml version='1.0' encoding='iso-8859-1'?><results><result cover="http://cps-static.rovicorp.com/3/jpg_170/mi0002/213/mi0002213251.jpg?partner=allrovi.com" title="hey-ya" artist="a.d.d." year="n/a" genre="pop/rock" details="http://www.allmusic.com/album/hey-ya-mw0001029555"/><result cover="http://cps-static.rovicorp.com/3/jpg_170/mi0003/152/mi0003152820.jpg?partner=allrovi.com" title="heyma" artist="abir nasraoui" year="n/a" genre="latin, pop/rock" details="http://www.allmusic.com/album/heyma-mw0002115440"/><result cover="http://cs-server.usc.edu:14186/album.jpg" title="heyla" artist="candy" year="2003" genre="r&b" details="http://www.allmusic.com/album/heyla-mw0000698853"/><result cover="http://cps-static.rovicorp.com/3/jpg_170/mi0002/172/mi0002172691.jpg?partner=allrovi.com" title="heya" artist="jimmy stallings" year="2003" genre="international" details="http://www.allmusic.com/album/heya-mw0000336392"/><result cover="http://cps-static.rovicorp.com/3/jpg_170/mi0003/361/mi0003361503.jpg?partner=allrovi.com" title="heya" artist="david jones" year="n/a" genre="electronic" details="http://www.allmusic.com/album/heya-mw0002388044"/></results> 

and part of code causing exception is:

saxbuilder builder = new saxbuilder();      string temp="";      out.println("inside servlet :::: ");      try     {         out.println("1. here");         document doc = builder.build(new stringreader(results));         out.println("2. here");         element root=doc.getrootelement();         out.println(root);           list resultchildren=root.getchildren();         out.println("3. here");         if(resultchildren.size()==0)         {             out.println("{\"results\":[]}");             return;         }                    temp="{\"results\":{\"result\":[";         for(int i=0;i<resultchildren.size();i++)         {             element tempelem = (element)(resultchildren.get(i));              if(i>0)             temp+=",";              if((request.getparameter("type")).equals("artists"))                                      temp+=parseartists(tempelem);                                else if((request.getparameter("type")).equals("albums"))                 temp+=parsealbums(tempelem);             else                                     temp+=parsesongs(tempelem);                                                                  }         temp+="]}}";     }     catch(jdomexception ex)     {         errors+="1.could not parse xml file";                }     catch(ioexception ex)     {         errors+="2.could not parse xml file";                } 

output generated using printwriter follows:

inside servlet ::::  1. here {"errors": {"1.could not parse xml file"}} 

thus, there exception thrown @ doc=builder.build(new stringreader(results));

kindly guide me through problem.

and after having printed stack trace (or @ least exception message) you'll see input xml not formed: there's attribute containing string "r&b". ampersand happens 1 of few characters has escaped, in case should read: "r&amp;b".


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -