Java 生成DOM文档对象时文件过早结束错误

Java 生成DOM文档对象时文件过早结束错误,java,exception,error-handling,Java,Exception,Error Handling,当我创建文档对象时,我遇到一个过早的文件结束错误。这段代码几天前还在运行,我不确定是什么原因导致它现在抛出错误 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(response)); Docum

当我创建文档对象时,我遇到一个过早的文件结束错误。这段代码几天前还在运行,我不确定是什么原因导致它现在抛出错误

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(response));
Document doc = builder.parse(is);
[致命错误]:1:1:文件过早结束

下面是我收到的响应xml。看起来很好

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <GetBatchFilesResponse xmlns="http://....">
            <GetBatchFilesResult>
                <BatchFile>
                    <Uri>someURI</Uri>
                    <ID>2025961</ID>
                    <FQName>someFileName</FQName>
                </BatchFile>
            </GetBatchFilesResult>
        </GetBatchFilesResponse>
    </soap:Body>
</soap:Envelope>

萨默里
2025961
文件名

该消息表示您的响应格式不正确。通常,当
XML
中有一个没有匹配结束标记的开始标记时,会弹出此消息。我想你也会得到一个空的回答。

我回到了我当地历史中的一些旧代码,它开始工作了。我对代码中的一些逻辑做了一些小的更改,出于某种原因,这些小的更改影响了它处理响应的方式。

尝试向xml添加新行,一些解析器需要它。

从那以后xml内容有变吗?因为错误消息提示它有…问题更可能出现在
响应
变量中。我已将我的xml响应添加到问题中供您查看。但它不是空的xml响应。响应中也没有丢失的标签您具体更改了什么?