开发者

Nested XML Transformers

I need to use the result of a javax.xml.transform.Transformer as an input to another Transformer, without saving the results to a file. That is...

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(source开发者_如何学C1, result1);

// Get contents of result1 into source2

transformer2.transform(source2, result2);


Replace

// Get contents of result1 into source2

with

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


You could make result1 a DOMResult, and then get the DOM from it after the first transform and use it to make source2 a DOMSource for the second transform.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜