240 APPENDIX A n MORE ADVANCED FEATURES APPENDIX A n MORE ADVANCED FEATURES
Exporting XML Entities With the entity mappings marked up for XML relational persistence, the generation of output from an existing set of persistent entities is fairly simple. By obtaining a session with the entity mode configured for Dom4J, the entity proxies retrieved from that session will be org.dom4j.Node instances that can be manipulated with the normal Dom4J API. To access a Session object in this mode, you first open a conventional session, and then invoke the getSession() method on it, passing EntityMode.DOM4J as the sole parameter thus: Session = sessionFactory.openSession(); Session xmlSession = session.getSession(EntityMode.DOM4J); Once an appropriate Dom4J document has been populated with the entities (extracted from Hibernate in the normal way), the session can be closed, and the Dom4J document can be treated as a self-contained entity, as shown in Listing A-8. Listing A-8. Exporting the Advert Entities Using Dom4J package sample.xml; import java.io.*; import java.util.*; import org.dom4j.*; import org.hibernate.*; import org.hibernate.cfg.Configuration; public class ExportXML { private static final SessionFactory sessionFactory = new Configuration() .configure().buildSessionFactory(); public static void main(String[] args) throws Exception { System.out.println(”Preparing the DOM Document”); Document document = DocumentHelper.createDocument(); Element root = document.addElement(”catalog”);
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.
This entry was posted
on Saturday, August 11th, 2007 at 9:13 am and is filed under tomcat.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.