XML Result
The following example shows using XML result class.
It provides a way of serializing results to an XML string.
The attribute xmlResultName="STUDENT"
allows us to specify the ROOT XML Tag name.
package com.bethecoder.tutorials.ibatis.tests.basic;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class XMLResultName {
/**
* @param args
* @throws IOException
* @throws SQLException
*/
public static void main ( String [] args ) throws IOException, SQLException {
Reader reader = Resources.getResourceAsReader ( "SqlMapConfig.xml" ) ;
SqlMapClient sqlMapClent = SqlMapClientBuilder.buildSqlMapClient ( reader ) ;
String studentXML = ( String ) sqlMapClent.queryForObject ( "Student.getXMLById" , 1 ) ;
System.out.println ( studentXML ) ;
}
}
It gives the following output,