you have to overwrite the toString method in class Book, and then iterate over the List to complete the xml. somthing like this:
[...] public String toString() { return "<book><id>" + id + "</id><name>" + name + "</name></book>"; } [...] public String list() { StringBuffer sb = new StringBuffer("<books>"); for(Iterator iter = bookDao.getList().iterator;iter.hasNext();) { sb.appengd(iter.next(()); } sb.append("</books>"); return sb.toString(); } [...] sorry if there is any syntax error, i've coded from scratch in my email client. best regards, Jorge. El vie, 29-06-2007 a las 14:50 +0800, chenshibing escribió: > Utilizing Struts2 xslt result type, how to convert a list of object to XML > file? > > > > Action: > > > > public class BookAction extends ActionSupport { > > private List<Book> bookList; > > > > public String list() throws Exception { > > bookList = bookDao.getList(); > > > > return SUCCESS; > > } > > } > > > > Model: > > > > public class Book { > > private Long id; > > private String name; > > > > // getter and setter. > > } > > > > I want to convert book list to a XML file as the following: > > > > <?xml version="1.0" encodeing="UTF-8"?> > > <books> > > <book> > > <id>1</id> > > <name>Thinking in Java</name> > > </book> > > <book> > > <id>2</id> > > <name>Effective Java</name> > > </book> > > ... > > </books> > > > > I’m new to XSLT, how to write an xsl template to get this job done? > > Any help will be appreciated. > > > > Real Chen > -- ____________________________________ Jorge Martin Cuervo Analista Programador Outsourcing Emarketplace deFacto Powered by Standards email <[EMAIL PROTECTED]> voz +34 985 129 820 voz +34 660 026 384 ____________________________________ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]