1
我有一個包含一個xml文件數據解析XML字符串SAX解析器機器人
字符串如
<?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>
此被保持在名爲標籤字符串;
我使用SAX解析器來檢索數據如下
SAXHelper sh = null;
try {
sh = new SAXHelper(newxml);
} catch (MalformedURLException e) {
e.printStackTrace();
}
sh.parseContent("");
部分saxhelper類
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;
}
}
的,但我與此錯誤顯示錯誤畸形結束。簡而言之,我想將一個xml字符串傳遞給sax解析器來設置並獲取結果。
04-05 11:25:18.390: W/System.err(2646): at org.apache.harmony.xml.ExpatParser.openUrl(ExpatParser.java:760)
04-05 11:25:18.398: W/System.err(2646): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:289)
04-05 11:25:18.398: W/System.err(2646): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:322)
04-05 11:25:18.398: W/System.err(2646): at .CompteDetails$SAXHelper.parseContent(CompteDetails.java:228)
04-05 11:25:18.398: W/System.err(2646): at .CompteDetails$loadingTask.doInBackground(CompteDetails.java:202)
04-05 11:25:18.398: W/System.err(2646): at .details.CompteDetails$loadingTask.doInBackground(CompteDetails.java:1)
04-05 11:25:18.398: W/System.err(2646): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-05 11:25:18.398: W/System.err(2646): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-05 11:25:18.398: W/System.err(2646): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-05 11:25:18.398: W/System.err(2646): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-05 11:25:18.398: W/System.err(2646): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-05 11:25:18.398: W/System.err(2646): at 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"?>..
細說嗎? – yakusha 2013-04-05 08:05:44