2010-12-13 60 views
3

我需要使用javax.xml.transform.Transformer的結果作爲另一個Transformer的輸入,而不將結果保存到文件中。這是...嵌套XML變形金剛

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); 

回答

1

更換

// Get contents of result1 into source2 

input2 = new StringReader(output1.getBuffer().toString()); 
source2 = new StreamSource(input2); 
output2 = new StringWriter(); 
result2 = new StreamResult(output2); 
0

你可以做一個RESULT1 DOMResult,然後經過從它那裏得到的DOM第一變換和用它來製作一個源2對爲DOMSource第二變換。