Which database are you using?

------Original Message------
From: Rashmi Rubdi
To: Apache Jakarta Taglibs help
ReplyTo: Apache Jakarta Taglibs help
Sent: Nov 24, 2006 12:26 PM
Subject: Re: Are there some examples of proper generating of XML from queries

Hi Alexander, 

I think you might want to consider using a MVC framework to generate the XML 
from the database.

*After* an XML file is generated then, you can easily extract the contents of 
the XML file with JSTL XML Tags.

There are many examples of how JSTL XML Tags are used in the JSTL Spec 
document. 
I'm refering to jstl-1_1-mr2-spec.pdf 

<!-- parse an XML document -->
<c:import url=”http://acme.com/customer?id=76567” var=”doc”/>
<x:parse doc=”${doc}” var=”parsedDoc”/>

<!-- access XML data via XPath expressions -->
<x:out select=”$parsedDoc/name”/>
<x:out select=”$parsedDoc/address”/>

<!-- set a scoped variable -->
<x:set var=”custName” scope=”request” select=”$parsedDoc/name”/>

You can either parse a document with x:parse and then access the contents of 
the XML or you can transform an xml file with xslt
and you can access the contents of XML this way also. 

There are many options and they are fully covered in the spec. 

There are no shortcuts, being a newbie myself I had to read the entire spec 
(which is very well written and easy to understand)
 to understand how JSTL works and what options are available.

-Rashmi

----- Original Message ----
From: Alexander Shopov <[EMAIL PROTECTED]>
To: taglibs-user@jakarta.apache.org
Sent: Friday, November 24, 2006 11:55:52 AM
Subject: Are there some examples of proper generating of XML from queries


Hi guys,
I am using JSTL to generate XML from simple queries.
I am doing it like the example I am giving below.

I am wondering - is this the right way? Should not XML be generated with 
some <x:out> expressions (where x is mapped to XML taglib)? Is there to 
do XPath expressions on variables like "result" from above?

I am reading JavaServer Pages Standard Tag Library specs Version 1.2 
from Sun but am undecided whether I am doing XML generation the proper 
way or just making ugly hacks.


========================================================================
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page";;
           xmlns:sql="http://java.sun.com/jsp/jstl/sql";;
           xmlns:c="http://java.sun.com/jsp/jstl/core";;
           version="2.0">

     <jsp:directive.page contentType="text/xml; charset=UTF-8"/>


     <countries>

         <sql:setDataSource dataSource="jdbc/wallet"
                            var="ds"/>
         <sql:query       var="result"
                          scope="page"
                          dataSource="${ds}">
             SELECT   ID as "id",
                      DESCRIPTION as "description"
             FROM     CURRENCY
             ORDER BY ID
         </sql:query>

         <c:forEach var="row" items="${result.rows}">
             <country>
                 <c:forEach var="column" items="${row}">
                     &lt;<c:out value="${column.key}"/>&gt;<c:out 
value="${column.value}"/>&lt;/<c:out value="${column.key}"/>&gt;
                 </c:forEach>
             </country>
         </c:forEach>

     </countries>

</jsp:root>
========================================================================



Kind regards:
al_shopov

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


 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

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



David Schwartz
[EMAIL PROTECTED]
Array Software Inc.  

Reply via email to