Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当文档以小写字母开头时,空手道HTML解析异常<;!doctype_Java_Html_Xhtml_Sax_Karate - Fatal编程技术网

Java 当文档以小写字母开头时,空手道HTML解析异常<;!doctype

Java 当文档以小写字母开头时,空手道HTML解析异常<;!doctype,java,html,xhtml,sax,karate,Java,Html,Xhtml,Sax,Karate,我试图运行一个空手道测试,调用一个URL上的GET,但我发现,当站点返回其时,如果您查看日志,空手道还告诉您它已将完整响应(将在response变量中提供)作为字符串保留,即使它无法将其“类型转换”为XML。顺便说一下,您甚至在responseBytes中有一个字节数组。因此,现在由您来做任何您想做的事情,例如,理论上您可以找到一个“宽松”的HTML解析器,并获得一个DOM树或其他东西 Given url 'http://www.google.com' When method GET Then

我试图运行一个空手道测试,调用一个URL上的GET,但我发现,当站点返回其
时,如果您查看日志,空手道还告诉您它已将完整响应(将在
response
变量中提供)作为字符串保留,即使它无法将其“类型转换”为XML。顺便说一下,您甚至在
responseBytes
中有一个字节数组。因此,现在由您来做任何您想做的事情,例如,理论上您可以找到一个“宽松”的HTML解析器,并获得一个DOM树或其他东西

Given url 'http://www.google.com'
When method GET
Then status 200
* print response
有几个提示,您可以尝试在
响应上执行字符串替换,然后尝试键入cast-to-XML,请参阅:

或者,您所要做的可能只是刮出一些数据,而一些正常的正则表达式匹配可能会这样做,请参考以下内容:


谢谢你,彼得,这非常有帮助。我用了字符串替换,它帮我整理好了!
[Fatal Error] :1:3: The markup in the document preceding the root element must be well-formed.
15:19:45.267 [main] WARN com.intuit.karate.FileUtils - parsing failed: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 3; The markup in the document preceding the root element must be well-formed.

<!doctype html><html .... blah
public static String toPrettyString(String raw) {
    raw = StringUtils.trimToEmpty(raw);
    try {
        if (Script.isJson(raw)) {
            return JsonUtils.toPrettyJsonString(JsonUtils.toJsonDoc(raw));
        } else if (Script.isXml(raw)) {
            return XmlUtils.toString(XmlUtils.toXmlDoc(raw), true);
        }
    } catch (Exception e) {
        logger.warn("parsing failed: {}", e.getMessage());
    }
    return raw;
}
public static final boolean isXml(String text) {
    return text.startsWith("<");
}
public static Document toXmlDoc(String xml) {
    ...

    Document doc = builder.parse(is);
    if (dtdEntityResolver.dtdPresent) { // DOCTYPE present
        // the XML was not parsed, but I think it hangs at the root as a text node
        // so conversion to string and back has the effect of discarding the DOCTYPE !
        return toXmlDoc(toString(doc, false));
Given url 'http://www.google.com'
When method GET
Then status 200
* print response