List of usage examples for org.dom4j Document add
void add(Node node);
Node
or throws IllegalAddException if the given node is not of a valid type. From source file:us.mn.state.health.lims.audittrail.daoimpl.AuditTrailDAOImpl.java
License:Mozilla Public License
/** * Convert to xml format by reading the table bases on it's id (dom4j) * @param table the table name/* w w w .j a v a2s.c o m*/ * @param id the primary id * @return xml string */ public String getXML(String table, String id) throws LIMSRuntimeException { org.hibernate.Session session = HibernateUtil.getSession(); org.hibernate.Session dom4jSession = session.getSession(org.hibernate.EntityMode.DOM4J); Element elem = (Element) dom4jSession.createQuery("from " + table + " where id=" + id).uniqueResult(); java.io.StringWriter sw = new java.io.StringWriter(); if (elem != null) { try { Document doc = DocumentHelper.createDocument(); doc.add(elem); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(sw, format); writer.write(doc); writer.flush(); writer.close(); return sw.toString(); } catch (Exception e) { //buzilla 2154 LogEvent.logError("AuditTrailDAOImpl", "getXML()", e.toString()); throw new LIMSRuntimeException("Error in AuditTrail getXML()", e); } } return null; }