cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ling Kok Choon <kokch...@brel.com>
Subject How to include a xml to a xsp ?
Date Mon, 07 Jun 2004 10:55:13 GMT
Hi all,

   currently, i am developing a program that able to merge data in the database and the data
in 
xml file. I have created a xsp file that able to read data from database and open a xml file.

the xsp will then read the xml file and replace some of the identifier with the data from

database.

  The problem is when the page is displayed, all the xml tag is shown... 

here is my xsp code :

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsp:page
          language="java"
          xmlns:xsp="http://apache.org/xsp"
	  xmlns:esql="http://apache.org/cocoon/SQL/v2"
	  xmlns:xsp-request="http://apache.org/xsp/request/2.0"
>

<xsp:structure>
  <xsp:include>java.util.StringTokenizer</xsp:include>
  <xsp:include>java.util.List</xsp:include>
  <xsp:include>java.util.Collections</xsp:include>
  <xsp:include>java.util.ArrayList</xsp:include>
  <xsp:include>java.io.File</xsp:include>
  <xsp:include>java.io.FileReader</xsp:include>
  <xsp:include>java.io.BufferedReader</xsp:include>
  <xsp:include>java.io.PrintWriter</xsp:include>
</xsp:structure>

<documents>

<xsp:logic>
   int page_id = 0;
   int folder_id = 0;      
   String isbn = null;
   String servletPath = "";
   String filePath = "E:/Tomcat-4.1/webapps/tpl/xml/";  
         
   servletPath = request.getServletPath();
   servletPath = servletPath.substring(1, servletPath.lastIndexOf(".") );   

   filePath = filePath + servletPath + ".xml";   
</xsp:logic>   

<esql:connection>
    <esql:pool>cmsDataSource</esql:pool>
     <esql:execute-query>
      <esql:query><xsp:expr>"select p.PAGE_ID, c.CATALOG_ISBN from catalog c,
page p where 
c.PAGE_ID=p.PAGE_ID and p.PAGE_PATH='" + servletPath + "'"</xsp:expr></esql:query>
 
    
      <esql:results>
        <esql:row-results>      
          <xsp:logic>                                      
             page_id = <esql:get-int column="PAGE_ID"/>;
             isbn = <esql:get-string column="CATALOG_ISBN"/>;             
          </xsp:logic>        
        </esql:row-results>      
      </esql:results>
    </esql:execute-query>
</esql:connection>

<xsp:logic>

if( page_id > 0 )
{  
    //here i read the xml file..
      BufferedReader br = new BufferedReader( new FileReader( new File(filePath) ) );    
 
      System.out.println("filePath : " + filePath );
      System.out.println("isbn : " + isbn );
      
      String data = null;
      //read the xml file and replace it with the data from database.
  while( ( data = br.readLine() ) != null )
  {
      if( data.indexOf("{isbn}") != -1 )
      {
          data = data.replaceAll( isbn, "{isbn}" );
      }            
</xsp:logic>
<xsp:expr>data</xsp:expr>
<xsp:logic>
  }
}
</xsp:logic>
</documents>
</xsp:page>

how to return the result (<xsp:expr>data</xsp:expr>), so cocoon able to parse
and transform the 
result with xsl file ?

Thanks you.

--------------------------------------------------------
Ling Kok Choon                         kokchoon@brel.com
Brel Software Pte Ltd                  Tel: 65-6272-6800
Blk 1003 Bukit Merah Central           Fax: 65-6272-2811
#07-01                                 http://www.brel.com
Singapore 159836                       06/07/04 18:55:13
                    
           Pls call us for the following services
         Web Creation, Web, Email & Domain Hosting
           Java Devt B2B B2C ASP CMS E-Commerce

--------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message