velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike J Boyersmith <mjboy...@us.ibm.com>
Subject anakia question and possible problem
Date Mon, 17 Jan 2005 22:57:53 GMT
Having problems getting anakia to transform $root.getChild calls..

I have the following xml data file

<?xml version="1.0" encoding="UTF-8"?>
<document>
   <foo name="waka">
     test
   </foo>
</document>

And the following vsl file (marked by !!! problem is here)

<html>
    <head>
        <META content="text/html; charset=UTF-8" 
http-equiv="Content-Type"/>
        <title> Main Title </title>
        <link href="mystyle.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <img src="overview_banner.jpg"/>
        <p class="LargeTitle"> 
         <!-- !!!!   PROBLEM IS HERE  !!!!!! -->
         <title>$root.getChild("foo").getText()</title>
        </p>
    </body>
</html>

and finally the following java code

-----------------------------------------
   .............
            SAXBuilder builder;
            Document root = null;
                builder = new 
SAXBuilder("org.apache.xerces.parsers.SAXParser" );
                root = builder.build( XMLFile );
           ............... 
            //Stuff the Document (or root Element) into the context:
            VelocityContext context = new VelocityContext();
            context.put("root", root );

            Template template =  null;
            template = Velocity.getTemplate(templateFile);
            .....
            BufferedWriter writer = writer = new BufferedWriter(
                        new FileWriter("./output/thePage.html"));

            if ( template != null)
                template.merge(context, writer);

            writer.flush();
            writer.close();
        ..........
------------------------------------------

When I execute the code and debug, I see the files get loaded and the 
merge, flush and close work fine.
However, my output html still has the literal string 

"$root.getChild("foo").getText()

embedded in it. when I check the log I see the following message

 "reference : template = StartPage.vsl [line 10,column 17] : 
 "$root.getChild("foo").getText() is not a valid reference.

I have tried every variation of xml and $root command I can think of 
and they all give me the same error. The only thing that doesn't produce 
an
error is if I just have $root.

any Idea why my getChild() call isn't working?

thanks for any help here...

Also, anyone have any other examples of using anakia, I can only find one 
that comes with the SDK...bah.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message