利用dom解析获取文件title时怎样忽略异常获取到title的文本值 开始做的时候遇到有些文件没有title元素的,程序会报空指针,然后我就catch空指针异常,返回一个空字符串。可是遇到有些文件又会报异常报错,比如
[Fatal Error] index.jsp:1:2: The markup in the document preceding the root element must be well-formed.
Exception in thread "main" org.xml.sax.SAXParseException; systemId: file:/home/lilisong/NetBeansProjects/WebApplication1/web/index.jsp; lineNumber: 1; columnNumber: 2; The markup in the document preceding the root element must be well-formed.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:253)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:288)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:205)
at com.bjsxt.test.CreateHtml2_1.getTitle(CreateHtml2_1.java:50)
at com.bjsxt.test.CreateHtml2_1.listFile(CreateHtml2_1.java:28)
at com.bjsxt.test.CreateHtml2_1.listFile(CreateHtml2_1.java:39)
at com.bjsxt.test.CreateHtml2_1.test(CreateHtml2_1.java:72)
at com.bjsxt.test.CreateHtml2_1.main(CreateHtml2_1.java:82)
Java Result: 1