在我的作业中,我应该解析一些sgml
文件。我使用SAXParser
。它适用于简单的xml
文件。但是当我想分析的功课sgml
文件会出现此错误:用萨克斯解析器解析sgml
Exception in thread "main" org.xml.sax.SAXParseException; systemId: file:///C:/Users/MarkaZ%20Computer%20RooZ/Documents/workspace/HW_02_IR/lewis.dtd; lineNumber: 2; columnNumber: 17; A '(' character or an element type is required in the declaration of element type "LEWIS".
我没有从dtd
文件的任何知识。我的代码是:
SAXParserFactory parserFactor = SAXParserFactory.newInstance();
SAXParser parser = parserFactor.newSAXParser();
SAXHandler handler = new SAXHandler();
parser.parse(new FileInputStream("reut2-000.sgm"), handler);
如何防止此错误?
原谅我的英语不好
如何向我们展示可用的XML和失败的SGML? –
@JanDoggen我使用本教程:http://www.javacodegeeks.com/2013/05/parsing-xml-using-dom-sax-and-stax-parser-in-java.html。它适用于教程中的示例xml。 –