private String containerXmlParser(String containerData) throws EpubParserException { //parsing container.xml
try {
String xml = containerData.replaceAll("[^\\x20-\\x7e]", "").trim(); //in case encoding problem
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xml)));
document.getDocumentElement().normalize();
if (document == null) {
throw new EpubParserException("Error while parsing container.xml");
}
Element rootElement = (Element) ((Element) document.getDocumentElement().getElementsByTagName("rootfiles").item(0)).getElementsByTagName("rootfile").item(0);
if (rootElement != null) {
String opfFile = rootElement.getAttribute("full-path");
if (opfFile == null) {
throw new EpubParserException("Missing root file element in container.xml");
}
//Log.d(TAG, "Root file: " + opfFile);
return opfFile; //returns opf file
}
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
return null;
}
EpubParser.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:r2-streamer-java
作者:
评论列表
文章目录