geir
On Mar 4, 2004, at 4:38 PM, Chris Hitzke wrote:
I am using Anakia along with JDOM and Velocity to transform my XML document into
HTML file. Below, is the code I wrote to make the transformation happen. But, it's not utilizing
the AnakiaTask class. How do I utilize the AnikiaTask class to convert XML to HTML using Velocity
template? I see how the it's done in the build.xml file (Anikia example). But, how do you do it
programatically? Please, respond. Thanks....
assumption: ==========
xml file =========== xml tags and info
.vm file ====== contains velocity code and html tags
html file ====== result of transforming xml file to .vm file
code for conversion ===================
Writer writer = null;
try { /* * and now call init */
Velocity.init();
/* * build a Document from our xml */
SAXBuilder builder; Document root = null;
try { builder = new SAXBuilder( "org.apache.xerces.parsers.SAXParser" ); root = builder.build(resultsFileName); } catch( Exception ee) { System.out.println("Exception building Document : " + ee); return; }
/* * now, make a Context object and populate it. */
VelocityContext context = new VelocityContext(); context.put("root", root);
/* * make a writer, and merge the template 'against' the context */
Template template = Velocity.getTemplate(velocityTemplateFileName);
writer = new BufferedWriter(new OutputStreamWriter(System.out)); template.merge( context , writer); } catch( Exception e ) { System.out.println("Exception : " + e); } finally { if ( writer != null) { try { writer.flush(); writer.close(); } catch( Exception ee ) { System.out.println("Exception : " + ee ); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Geir Magnusson Jr 203-247-1713(m) [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
