Java 错误:';com.sun.org.apache.xml.internal.utils.WrappedRuntimeException:xml文档结构必须在同一实体中开始和结束

Java 错误:';com.sun.org.apache.xml.internal.utils.WrappedRuntimeException:xml文档结构必须在同一实体中开始和结束,java,xml,xslt,Java,Xml,Xslt,在使用xslt将xml转换为html时,我遇到了一个问题 伪代码如下 TransformerFactory tFactory = TransformerFactory.newInstance(); Source xslDoc = new StreamSource( xsltPath ); Source xmlDoc = new StreamSource( xmlPath ); oFileOutputStream=new FileOutputStream( htmlOutputPath ); ht

在使用xslt将xml转换为html时,我遇到了一个问题
伪代码如下

TransformerFactory tFactory = TransformerFactory.newInstance();
Source xslDoc = new StreamSource( xsltPath );
Source xmlDoc = new StreamSource( xmlPath );
oFileOutputStream=new FileOutputStream( htmlOutputPath );
htmlFile = oFileOutputStream;
Transformer transformer = tFactory.newTransformer( xslDoc );
transformer.transform( xmlDoc, new StreamResult( htmlFile ) );
错误如下:

ERROR:  'XML document structures must start and end within the same entity.'
ERROR:  'com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: XML document structures must start and end within the same entity.'
我的xml和xslt文件是正确的。若我使用相同的代码main方法来测试它的工作性能,但相同的代码并没有在项目中解析。
有什么想法吗

我认为您的环境中可能存在一些库冲突或版本不同。请检查所有相关的库


似乎您在transformer仍在工作时关闭了流。请检查您是否未关闭任何流资源。

我很好奇。您所说的“测试其工作但不在项目中解析的主要方法”是什么意思?你是说代码正在使用一个示例测试用例,但正在使用真实数据吗?这个错误表明XML文件不正确。检查是否有格式不正确的CDATA节。再次检查xml文件,