Hello!
 
I want to write a Servlet basing on the velocity-template-engine.
Everything works fine, I have only difficultiies reading a XML file with SAX
and getting the sax-events into the velocity-context.

Could anyone give me a hint how to tell SAX to work with Velocity ?
 
My idea would be the following, but it does not work...

//*************************************

public class TestServlet extends VelocityServlet implements ContentHandler {

String testString;

 protected Properties loadConfiguration(ServletConfig config )
        throws IOException, FileNotFoundException    {
   //......
 }


  /*** SAX - Methods ***********************/    
   
    
    public void startDocument() throws SAXException {           
       // ......
    }      
       
      
    public void startElement( String namespaceURI, String localName, String
qName, Attributes atts) throws    SAXException {        
      
    // element "page" in my xml-file
        if ( qName.equalsIgnoreCase( "page" )) {
                
        // just a very simple event..
                testString = "testString";              
                
        }

/*

... other possible Sax-Events

*/

 public Template handleRequest( HttpServletRequest request,
        HttpServletResponse response, Context ctx )    {        


       try {                            
                
                String parserClass ="org.apache....."
                TestServlet testServlet = new TestServlet();                    
        
                XMLReader reader = 
XMLReaderFactory.createXMLReader(parserClass);               
                reader.setContentHandler(testServlet);
                reader.parse( "xml/test.xml");
       } catch 
          // ..Exceptions ...


// -> THIS does not work, in the velocity-template I get for 'testString'
only $testString ...
ctx.put( "testString", testString);



//... end of velocity-servlet


/******************************/

I have no problems getting variables etc. into the velocity-context.
My problem here I think are the SAX-Events...


Thanks in advance !

Peter


-- 
View this message in context: 
http://www.nabble.com/Velocity-Servlet-and-Sax-Events-tf3420318.html#a9532823
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to