如何解决Groovy的XmlSlurper由于DOCTYPE和DTD限制拒绝解析HTML?
发布时间:2020-12-14 16:34:00 所属栏目:大数据 来源:网络整理
导读:我正在尝试在 HTML覆盖率报告中复制一个元素,因此覆盖率总计将显示在报告的顶部以及底部. 因此,HTML开始,我相信是格格不入的: ?xml version="1.0" encoding="UTF-8"?!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1
我正在尝试在
HTML覆盖率报告中复制一个元素,因此覆盖率总计将显示在报告的顶部以及底部.
因此,HTML开始,我相信是格格不入的: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <link rel="stylesheet" href=".resources/report.css" type="text/css" /> <link rel="shortcut icon" href=".resources/report.gif" type="image/gif" /> <title>Unified coverage</title> <script type="text/javascript" src=".resources/sort.js"></script> </head> <body onload="initialSort(['breadcrumb','coveragetable'])"> Groovy的XmlSlurper抱怨如下: doc = new XmlSlurper( /* false,false,false */ ).parse("index.html") [Fatal Error] index.html:1:48: DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true. DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true. 启用DOCTYPE: doc = new XmlSlurper(false,true).parse("index.html") [Fatal Error] index.html:1:148: External DTD: Failed to read external DTD 'xhtml1-strict.dtd',because 'http' access is not allowed due to restriction set by the accessExternalDTD property. External DTD: Failed to read external DTD 'xhtml1-strict.dtd',because 'http' access is not allowed due to restriction set by the accessExternalDTD property. doc = new XmlSlurper(false,true,because 'http' access is not allowed due to restriction set by the accessExternalDTD property. doc = new XmlSlurper(true,true).parse("index.html") External DTD: Failed to read external DTD 'xhtml1-strict.dtd',because 'http' access is not allowed due to restriction set by the accessExternalDTD property. doc = new XmlSlurper(true,because 'http' access is not allowed due to restriction set by the accessExternalDTD property. 所以我想我已经涵盖了所有的选择.必须有一种办法让这个工作不用诉诸正义,并冒着“托尼小马”的愤怒. 解决方法
啧啧.
parser=new XmlSlurper() parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl",false) parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false); parser.parse(it) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |