我需要使用 javax.xml.transform.Transformer 的结果作为另一个 Transformer 的输入,而不将结果保存到文件中。那就是……
Reader input = new StringReader(xml); // Where xml is a String
StringWriter output = new StringWriter();
StreamSource source = new StreamSource(input);
StreamResult result = new StreamResult(output);
transformer1.transform(source1, result1);
// Get contents of result1 into source2
transformer2.transform(source2, result2);
最佳答案
替换
// Get contents of result1 into source2
与
input2 = new StringReader(output1.getBuffer().toString());
source2 = new StreamSource(input2);
output2 = new StringWriter();
result2 = new StreamResult(output2);
关于java - 嵌套的 XML 转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4430390/