下面列出了怎么用org.apache.commons.io.input.XmlStreamReader的API类实例代码及写法,或者点击链接到github查看源代码。
public Feed parseFeed(Feed feed) throws SAXException, IOException,
ParserConfigurationException, UnsupportedFeedtypeException {
TypeGetter tg = new TypeGetter();
TypeGetter.Type type = tg.getType(feed);
SyndHandler handler = new SyndHandler(feed, type);
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser saxParser = factory.newSAXParser();
File file = new File(feed.getFile_url());
Reader inputStreamReader = new XmlStreamReader(file);
InputSource inputSource = new InputSource(inputStreamReader);
saxParser.parse(inputSource, handler);
inputStreamReader.close();
return handler.state.feed;
}
/**
* Creates an XML InputSource from an InputStream with the correct
* encoding.
*
* @param inputStream
* @return an input source for an XML parser
* @throws IOException
*
* @see {@link XmlStreamReader}
*/
public static InputSource getInputSource(final InputStream inputStream) throws IOException {
final Reader reader = new XmlStreamReader(inputStream);
return new InputSource(reader);
}