我想用XMLReader解析位于SD中的xml文件
我有这段代码:
private RSSFeed getFeed(String urlToRssFeed)
{
try
{
// setup the url
URL url = new URL(urlToRssFeed);
// create the factory
SAXParserFactory factory = SAXParserFactory.newInstance();
// create a parser
SAXParser parser = factory.newSAXParser();
// create the reader (scanner)
XMLReader xmlreader = parser.getXMLReader();
// instantiate our handler
RSSHandler theRssHandler = new RSSHandler();
// assign our handler
xmlreader.setContentHandler(theRssHandler);
// get our data through the url class
InputSource is = new InputSource(url.openStream());
// perform the synchronous parse
xmlreader.parse(is);
// get the results - should be a fully populated RSSFeed instance,
// or null on error
return theRssHandler.getFeed();
}
catch (Exception ee)
{
// if you have a problem, simply return null
return null;
}
}
但这适用于在线xml文件 要打开存储在SD卡中的xml文件,必须进行哪些更改?
答案 0 :(得分:1)
您是否添加了
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
到您的清单文件?