If you are OK with using a map, using a rowhandler to generate the xml
will be very simple, and not measurably slower than the current
implementation.
Again, I think this is truly a better approach. Why?
It's fast, because it only goes through the returned results once.
It's very light weight because only one Map from your query is in
memory at any time.
It is simpler, because...it's just text.
Because it's just text, so it has none of the memory baggage that
Document does.
It has zero dependencies on any external xml libraries.
Here is an example:
===
import com.ibatis.sqlmap.client.event.RowHandler;
import java.util.Map;
public class XmlRowHandler implements RowHandler {
private StringBuffer xml = new StringBuffer("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>");
private String container;
public XmlRowHandler(String container) {
this.container = container;
}
public void handleRow(Object object) {
Map map = (Map) object;
for (Object key : map.keySet()) {
xml.append("<").append(key).append(">");
xml.append(map.get(key));
xml.append("</").append(key).append(">");
}
}
public String getXml() {
return wrap(xml, container);
}
private String wrap(StringBuffer xml, String container) {
return "<" + container + ">" + xml.toString() + "</" + container + ">";
}
}
===
It's yours, run with it. ;-)
Larry
On 6/4/06, Shepherdz <[EMAIL PROTECTED]> wrote:
Bill,
I would say that we are in the same boat. In our platform, we want to use
AJAX in the web tier. Therefore xml representation is more straight forwards
than other approaches. We want to build a generic object structure using
xml. Thus we can get rid of some meaningless reflections in our platform.
We have tried Hibernate. Unfortunately, its performance is poor in
processing large result. IBatis is much faster.
In the current situation, I recommend you to use HashMap result instead of
xml, which is also a generic structure. Then convert the Map to xml in your
own code. Although this approach will delay your program a little bit, it is
acceptable.
Actually, I'm now trying to modify the source of IBatis to enable a better
xml support. However, it seems the IBatis team has planned to get rid of xml
support from 3.0's core. If so, using HashMap result may be a better
decision in the current status. It can be also efficient and generic, with
only a little cost.
Anyway, we insist that xml support is very important, even more important
than beans, for it is a more generic and flexible representation. No matter
how 3.0 is implemented, a powerful and efficient support of xml result
mapping is a very competitive feature.
--
View this message in context:
http://www.nabble.com/When-returning-mutiple-objects-and-transforming-%22directly-to-xml-t1718587.html#a4709836
Sent from the iBATIS - User - Java forum at Nabble.com.