[英]Append StringReader For Multiple Entries
I'm creating a program in Java that reads a string of XSL-FO code, populates the empty fields with app data, and adds it to a StringReader, to eventually be set as an InputSource for a web dispatcher. 我正在用Java创建一个程序,它读取一串XSL-FO代码,用app数据填充空字段,并将其添加到StringReader,最终设置为Web调度程序的InputSource。
I already have the code to find and populate the blank template, and now I need to loop through the template X number of times to create X instances of the same document, put together all as a single document. 我已经有了查找和填充空白模板的代码,现在我需要循环遍历模板X次,以创建同一文档的X实例,将所有文档放在一起作为单个文档。
Psuedocode: 伪代码:
StringReader reader = new StringReader();
for (Iterator i = Object.iterator(); i.hasNext();
{
Object o = (Object) i.next();
reader.append(populateObject(o);
}
InputSource isource = new InputSource(reader);
StringReader, however, doesn't have an append function, and probably isn't meant to have one either. 但是,StringReader没有附加函数,也可能不具备附加函数。 So, how can I create an InputSource that will satisfy the need to have a full, accurate reference to my XML code, that can be read by an InputSource object?
那么,我如何创建一个InputSource来满足对我的XML代码的完整,准确的引用的需求,可以通过InputSource对象读取?
You could try doing all the appending before-hand: 您可以尝试先做所有附加操作:
StringBuilder sb = new StringBuilder();
for (...)
sb.append(populateObject(obj));
StringReader reader = new StringReader(sb.toString());
Use StringBuffer
if you're using a Java version below 5. 如果您使用的Java版本低于5,请使用
StringBuffer
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.