No grammar constraints (DTD or XML Schema) 处理后导致junit停顿异常

来源:互联网 发布:mac gcc include 编辑:程序博客网 时间:2024/06/05 04:24

今天使用eclipse后,看到xml中的警告图标,提示:No grammar constraints (DTD or XML Schema) referenced in the document. 异常,按照网上推荐的方法在xml中加入了dtd描述:

Java代码  收藏代码
  1. 方法一:常用方法   关闭XML验证  
  2. 工具栏:windows => preferences => xml => xml files => validation => Indicate when no grammar is specified:选择Ignore即可。  
  3. 方法二:(个人推荐)  
  4. 添加 内容如下  
  5. <?xml version="1.0" encoding="UTF-8" standalone="no"?>  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/2002/xmlspec/dtd/2.10/xmlspec.dtd">  

 结果,在使用Junit测试代码进行测试时,每次都停在读取xml文件【Document document = reader.read(read);】的地方很长时间。

Java代码  收藏代码
  1. in = new ByteArrayInputStream(result.getBytes());  
  2.             SAXReader reader = new SAXReader();  
  3.             Reader read = new InputStreamReader(in,"UTF-8");  
  4.             Document document = reader.read(read);  
  5.             return document.getRootElement();  

 

查了N多资料都快把我逼疯了。回来在logback日志框架怀疑的时候,有个提示说xml的内容不规范,突然想到通过去掉DTD描述进行测试。结果读取文件正常了。

看来使用Dom4J将字符串转换为Document的时候,对于不规范的内容,会导致读取转换超时,可惜又不报个错,害我找半天。

还是应了那句话,不作死就不会死。像我这种有强迫症的人,得到的是多么痛的领悟,半天时候又耗费了。今天又要加班了!

0 0