ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From netsql <cekven...@gmail.com>
Subject Re: ibatis to return xml instead of arraylist (of hashmap).
Date Sat, 17 Mar 2007 01:53:22 GMT
No, I have not tried that yet.
I was doing something similar to what Larry showed.
But now I am switching to type=XML.

I did not like having to jack w/ Xstream re-mapping.
THANK YOU!
.V
ps: and congrats on the book, I saw it at a bookstore. If anyone goes to SF
for Javaone or otherwise, ping me at vic at pointcast dot com.

On 3/15/07, Clinton Begin <clinton.begin@gmail.com> wrote:
>
> Vic,
>
> I'm assuming you've already tried <resultMap ... type="xml"> to get a list
> of XML documents back?
>
> Clinton
>
> On 3/15/07, Larry Meadors <lmeadors@apache.org> wrote:
> >
> > Vic,
> >
> > You could write a row handler to take the returned maps and a string
> > builder to create xml.
> >
> > One class would handle all of your requirements.
> >
> > Something like this is close - testing is an exercise left to the
> > reader. ;-)
> >
> > ===
> > public class MapToXmlRowHandler
> >         implements RowHandler
> > {
> >     private String wrapper;
> >     private String item;
> >     private StringBuilder builder;
> >
> >
> >     public MapToXmlRowHandler(String wrapper, String item) {
> >         this.wrapper = wrapper;
> >         this.item = item;
> >         builder = new StringBuilder();
> >     }
> >
> >     public void handleRow(Object object) {
> >         Map<String, Object> m = (Map<String, Object>) object;
> >
> >         builder.append("<").append(item).append(">");
> >
> >         for(String key : m.keySet()){
> >             // todo: make sure these values are xml friendly
> >             builder.append ("<").append(key).append(">")
> >                    .append(m.get(key))
> >                    .append("</").append(key).append(">");
> >         }
> >
> >         builder.append ("</").append(item).append(">");
> >     }
> >
> >     public String getResultsAsXml(){
> >         StringBuilder result = new StringBuilder("<" + wrapper + ">")
> >                 .append(builder)
> >                 .append("</").append(wrapper).append(">");
> >         return result.toString();
> >     }
> >
> > }
> > ===
> >
> > Larry
> >
> >
> > On 3/15/07, netsql < cekvenich@gmail.com> wrote:
> > > In the past I allways returned arraylist of hashmap and that works
> > EXCLENT.
> > >
> > > I now want to return xml. I saw some notes on xstream and it works but
> > not
> > > so well, I do not like the xml it makes.
> > >
> > > Is there snipets or more ideas to help me?
> > >
> > > tia,
> > > .V
> > >
> >
>
>

Mime
View raw message