Parse XML String to Sax parser android -


i have string containing xml file data

such as

<?xml version="1.0" encoding="utf-8"?>  <data>  <type> <lory>vroom</lory> <car>crack</car> </type>  <type> <lory>doom</lory> <car>chack</car> </type>  </data> 

this kept in string named label;

i use sax parser retrieve data follows

saxhelper sh = null;              try {                 sh = new saxhelper(newxml);             } catch (malformedurlexception e) {                 e.printstacktrace();             }              sh.parsecontent(""); 

part of saxhelper class

class saxhelper {           public hashmap<string, string> userlist = new hashmap<string, string>();         private string data;          public saxhelper(string url1) throws malformedurlexception {             this.data = new string(url1);         }          public rsshandler parsecontent(string parsecontent) {             rsshandler df = new rsshandler();             try {                  saxparserfactory spf = saxparserfactory.newinstance();                 saxparser sp = spf.newsaxparser();                 xmlreader xr = sp.getxmlreader();                 xr.setcontenthandler(df);                 xr.parse(data);              } catch (exception e) {                 e.printstacktrace();             }             return df;         }     } 

but end error showing malformation error. short want pass xml string sax parser set , result.

04-05 11:25:18.390: w/system.err(2646):     @ org.apache.harmony.xml.expatparser.openurl(expatparser.java:760) 04-05 11:25:18.398: w/system.err(2646):     @ org.apache.harmony.xml.expatreader.parse(expatreader.java:289) 04-05 11:25:18.398: w/system.err(2646):     @ org.apache.harmony.xml.expatreader.parse(expatreader.java:322) 04-05 11:25:18.398: w/system.err(2646):     @ .comptedetails$saxhelper.parsecontent(comptedetails.java:228) 04-05 11:25:18.398: w/system.err(2646):     @ .comptedetails$loadingtask.doinbackground(comptedetails.java:202) 04-05 11:25:18.398: w/system.err(2646):     @ .details.comptedetails$loadingtask.doinbackground(comptedetails.java:1) 04-05 11:25:18.398: w/system.err(2646):     @ android.os.asynctask$2.call(asynctask.java:185) 04-05 11:25:18.398: w/system.err(2646):     @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:306) 04-05 11:25:18.398: w/system.err(2646):     @ java.util.concurrent.futuretask.run(futuretask.java:138) 04-05 11:25:18.398: w/system.err(2646):     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1088) 04-05 11:25:18.398: w/system.err(2646):     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:581) 04-05 11:25:18.398: w/system.err(2646):     @ java.lang.thread.run(thread.java:1019) 04-05 11:25:18.402: w/system.err(2646): caused by: java.net.malformedurlexception: protocol not found: <?xml version="1.0" encoding="utf-8"?>.. 

you passing raw xml:

<?xml version="1.0" encoding="utf- 

hence exception:

04-05 11:25:18.402: w/system.err(2646): caused by: java.net.malformedurlexception: protocol not found: <?xml version="1.0" encoding="utf-8"?> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -