有一个xml文件,使用
org.xml.sax.XMLReader和org.dom4j.io.SAXReader解析结果不同,是什么原因?try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.parse
(new InputSource(new java.io.FileReader("E:\\office\\doc\\java_doc\\Html2XLIFF\\lib\\content.zh123.xml")));
System.out.println("XMLReader ok");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
SAXReader parser = new SAXReader();
parser.read(new File
("E:\\office\\doc\\java_doc\\Html2XLIFF\\lib\\content.zh123.xml"));
System.out.println("SAXReader ok");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}执行上面的代码,结果得到:
[Fatal Error] :2:27095: The element type "text:p" must be terminated by the matching end-tag "</text:p>".
org.xml.sax.SAXParseException: The element type "text:p" must be terminated by the matching end-tag "</text:p>".
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at test.Test.main(Test.java:48)SAXReader ok很奇怪,是不是org.xml.sax.XMLReader有bug啊?csdn不支持附件,我把xml文件放网盘上面了。
http://dl-web.dropbox.com/u/5677556/content.zh__.xml
org.xml.sax.XMLReader和org.dom4j.io.SAXReader解析结果不同,是什么原因?try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.parse
(new InputSource(new java.io.FileReader("E:\\office\\doc\\java_doc\\Html2XLIFF\\lib\\content.zh123.xml")));
System.out.println("XMLReader ok");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
SAXReader parser = new SAXReader();
parser.read(new File
("E:\\office\\doc\\java_doc\\Html2XLIFF\\lib\\content.zh123.xml"));
System.out.println("SAXReader ok");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}执行上面的代码,结果得到:
[Fatal Error] :2:27095: The element type "text:p" must be terminated by the matching end-tag "</text:p>".
org.xml.sax.SAXParseException: The element type "text:p" must be terminated by the matching end-tag "</text:p>".
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at test.Test.main(Test.java:48)SAXReader ok很奇怪,是不是org.xml.sax.XMLReader有bug啊?csdn不支持附件,我把xml文件放网盘上面了。
http://dl-web.dropbox.com/u/5677556/content.zh__.xml
你把xml文件贴出来
你自己看下异常.
检查一下你的jdk版本,是否更新到最新。
不是jdk的问题,我用的也是1.6,就是报这个错误。
需要结束标记,如下。上面那个是html的写法
<text:p text:style-name="P2" ></text:p>
加了</text:p>一样报错,不是这个原因。