我正在尝试解析现有的xhtml文件,以将其他正文内容添加到该文件中.我使用以下代码:
首先,我正在阅读Jsoup中的身体,我正在尝试将其放入Xhtml文件中
Document doc = Jsoup.parse(readFile, "UTF-8");
Elements content = doc.getElementsByTag("body");
try {
Document document=null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Create the builder and parse the file
document = (Document)factory.newDocumentBuilder().parse(finalFile);
//document.getElementsByTagName("body")append(content.toString());
//document=parserXML(finalFile);
document.getElementsByTag("body").append(content.toString());
} catch (SAXException e) {
System.out.println("SAXException>>>>>>");
e.printStackTrace();
} catch (ParserConfigurationException e) {
System.out.println("in parser configuration Exception block>>>>>>");
e.printStackTrace();
}
但我得到以下例外:
[Fatal Error] ResultParsedFile.html:1:1: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.converter.typeconverter.EmailTypeConverter.readHTML(EmailTypeConverter.java:101)
at com.converter.typeconverter.EmailTypeConverter.callTika(EmailTypeConverter.java:64)
at com.converter.master.ApplicationMain.main(ApplicationMain.java:64)
请帮助我解决这个问题……
提前致谢…