You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeff Smith <je...@centralscheduling.net> on 2003/04/08 20:56:27 UTC

[OT] Integrating dynamic XML generation with Struts apps

This question may be a little off topic, but I think a good solution will be
of interest to the struts-user community so here goes...

I have a number of pages in my app that display XML docs using XSL-like
transformations in the JSP (actually JSTL x: tags). I've implemented these
pages by using a prep-stage Action which dynamically creates the XML doc
from the database and places it in the session scope, then forwards to the
display JSP.

It works great. But so far, I've been generating the XML laboriously using
DOM traversal and node creation calls hard coded into the Action. I have at
least a dozen such pages to generate and I don't relish the thought of doing
all of them in this hard-coded manner. What I'd like to do is create the XML
files declaratively, using an XML template that includes SQL calls, and
perhaps some references to a Map of run-time parameters.

I looked at Doug Tidwell's article on the IBM site about doing
template-based XML generation, but it doesn't go far enough. (It does not
support such things as nested template specs for example.)

So I started looking around. I found that Oracle has an XML SQL Utility
suite which appears to do much of what I'm after, but it only works for
Oracle.

I also came across Jdbc2xml - a utility class from Intelligent Systems
Research, but the documentation is a bit sparse and I'm concerned that it
might not be very robust.

Does anybody know of any other tools like this?

Jefficus


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Integrating dynamic XML generation with Struts apps

Posted by Kris Schneider <kr...@dotech.com>.
The closest thing I've seen to your example is Oracle's XSQL Pages (included in
their XDK for Java). From the docs:

The XSQL Servlet is designed to run on any Java VM, using any JDBC driver,
against any database.

If it looks useful, make sure to check out the license.

Quoting Jeff Smith <je...@centralscheduling.net>:

> Aah. Now I see what you are suggesting. (I think :-)
> 
> I don't think I provided enough detail in my problem description.
> 
> What I am trying to do is construct a document by drawing information from
> a
> variety of tables and interleaving the results. And much of that structure
> might be dependant on the actual data extracted.
> 
> Allow me to provide a simple example. I have a customer table with 10,000
> customers, an invoice table with 50,000 invoices and an order-item table
> with 200,000 individual order records. When Mr. Jones logs in, I want to
> show him his most recent invoice/order.
> 
> So I need to construct an XML document on the fly that contains his
> customer
> information, the ID of his most recent order and all the order-items that
> are part of that order. With that document in scope, I can then render it
> into a pretty display for him to view, using XSL:FO or CSS or whatever.
> 
> Your solution will work, but I think I either have to write a lot of
> Action-time code to ensure that all the necessary table queries have been
> executed and put into scope or else I have to write a lot of "code" in the
> JSP. From my very lazy perspective, this is too much explicit coding and
> I'm
> concerned that the resulting JSP file will be so laden with business logic
> to construct the table information, that there is little hope of having a
> graphic designer work the file to change the look.
> 
> What I'm looking for instead is a mechanism that lets me create a template
> file like this:
> <invoice sql="SELECT * FROM InvoiceTable WHERE InvID=$ParamOrderID">
>     <customer sql="SELECT * FROM Customers WHERE
> CustID=$invoice.CustomerID>
>         <name><SQLVALUE id="customer.Name"/></name>
>         <phone><SQLVALUE id="customer.Phone"/></phone>
>     </customer>
>     <items sql="SELECT * FROM OrderTable WHERE OrderID=$ParamOrderID">
>         <item>
>         <itemname><SQLVALUE id="items.Name"></itemname>
>         <quantity><SQLVALUE id="items.Number"></quantity>
>         <price><SQLVALUE id="items.Cost"></itemnaem>
>         </item>
>     </items>
> </invoice>
> 
> Loading this template and invoking it with Mr. Jones' order id provided as
> a
> param would create this XML file:
> <invoice>
>     <customer>
>         <name>Mr. Jones</name>
>         <phone>555-1435</phone>
>     </customer>
>     <items>
>         <item>
>             <itemname>Widget</itemname>
>             <quantity>50</quantity>
>             <price>1.25</price>
>         </item>
>         <item>
>             <itemname>Flanges</itemname>
>             <quantity>120</quantity>
>             <price>0.56</price>
>         </item>
>     </items>
> </invoice>
> 
> This document would be extremely easy to render in my JSP, without
> confusing
> the display with a lot of logic and sql calls and such.
> 
> I hope that's clearer.
> 
> Jefficus
> 
> 
> ----- Original Message -----
> From: "Kris Schneider" <kr...@dotech.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Tuesday, April 08, 2003 10:01 PM
> Subject: Re: [OT] Integrating dynamic XML generation with Struts apps
> 
> 
> > Yup, I got the part about the problem being the dynamic generation of the
> XML.
> > That's what the <c:forEach> element was supposed to address. I'm assuming
> the
> > XML you're currently generating as a DOM tree ends up looking something
> like
> > what Oracle's XML SQL Utility (XSU) outputs from a ResultSet:
> >
> > <ROWSET>
> >    <ROW num="1">
> >      <EMPNO>7369</EMPNO>
> >      <ENAME>Smith</ENAME>
> >      <JOB>CLERK</JOB>
> >      <MGR>7902</MGR>
> >      <HIREDATE>12/17/1980 0:0:0</HIREDATE>
> >      <SAL>800</SAL>
> >      <DEPTNO>20</DEPTNO>
> >    </ROW>
> >    <!-- additional rows ... -->
> > </ROWSET>
> >
> > To do this dynamically, you can leverage a couple of JSTL utility
> > classes/interfaces. If you've got a ResultSet, you can use:
> >
> > import javax.servlet.jsp.jstl.sql.Result;
> > import javax.servlet.jsp.jstl.sql.ResultSupport;
> > ...
> > Result result = ResultSupport.toResult(resultSet);
> > request.setAttribute("dbResult", result);
> >
> > Then, in a JSP, you can traverse dbResult:
> >
> > <rowset>
> >    <%-- ${dbResult.rows} is a java.util.SortedMap[] --%>
> >    <c:forEach var="rowMap" items="${dbResult.rows}" varStatus="rowNum">
> >      <row num="<c:out value="${rowNum.count}"/>">
> >        <c:forEach var="rowEntry" items="${rowMap}">
> >          <c:set var="startTag"><<c:out value="${rowEntry.key}"/>></c:set>
> >          <c:set var="endTag"></<c:out value="${rowEntry.key}"/>></c:set>
> >          <c:out value="${startTag}" escapeXml="false"/>
> >            <c:out value="${rowEntry.value}"/>
> >          <c:out value="${endTag}" escapeXml="false"/>
> >        </c:forEach>
> >      </row>
> >    </c:forEach>
> > </rowset>
> >
> > Admittedly, I haven't tried the constructs for "startTag" and "endTag",
> but
> > something like it ought to be doable ;-). You might also be able to
> accomplish
> > something similar by using org.apache.commons.beanutils.RowSetDynaClass
> instead
> > of JSTL's Result.
> >
> > I'm not sure I understand what you mean by "batch", and I certainly don't
> know
> > what your requirements are for integrating with other logic tags, but the
> > <x:transform> tag is pretty flexible. The value of its "xslt" attribute
> can be a
> > String, Reader, or javax.xml.transform.Source. You can also capture the
> result
> > of the transformation by using either the "var" attribute to export a DOM
> > document, or the "result" attribute to use an existing
> javax.xml.transform.Result.
> >
> > Jeff Smith wrote:
> > > My problem is not in how to transform the XML doc for display. The
> problem
> > > is dynamically generating the XML in the first place - from data fields
> held
> > > in my db.
> > >
> > > Once I've got the XML file, the display-time transformations can be
> done
> in
> > > dozens of different ways. I actually do something not unlike your
> > > suggestion. However, I can't use a "batch" style sheet as you've
> sketched,
> > > because I need to integrate the transformation with other run-time
> logic
> > > tags.
> > >
> > > Jefficus
> > >
> > > ----- Original Message -----
> > > From: "Kris Schneider" <kr...@dotech.com>
> > > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > > Sent: Tuesday, April 08, 2003 2:00 PM
> > > Subject: Re: [OT] Integrating dynamic XML generation with Struts apps
> > >
> > >
> > >
> > >>If you're already using JSTL, why not use JSP to create *and* transform
> > >
> > > the XML:
> > >
> > >><x:transform xslt="${stylesheet}">
> > >>  <%-- body specifies dynamic XML document and transform params --%>
> > >>  <c:forEach var="row" items="${dataCollection}">
> > >>    <row>
> > >>      ...
> > >>    </row>
> > >>  </c:forEach>
> > >></x:transform>
> > >>
> > >>Quoting Jeff Smith <je...@centralscheduling.net>:
> > >>
> > >>
> > >>>I've looked briefly at Cocoon. It appears to be massively overkill for
> > >>
> > > my
> > >
> > >>>rather simple needs. Although if somebody out there is using it to
> > >>
> > > simply
> > >
> > >>>create dynamic XML to feed a struts app, I'd love to hear about your
> > >>>experiences.
> > >>>
> > >>>Jefficus
> > >>>
> > >>>----- Original Message -----
> > >>>From: "Mike Jasnowski" <mj...@bea.com>
> > >>>
> > >>>
> > >>>>Not sure if this is what you're after exaclt, but have you looked at
> > >>>
> > >>>Cocoon?
> > >>>
> > >>>>-----Original Message-----
> > >>>>From: Jeff Smith [mailto:jeffs@centralscheduling.net]
> > >>>>Sent: Tuesday, April 08, 2003 2:56 PM
> > >>>>To: Struts Users Mailing List
> > >>>>Subject: [OT] Integrating dynamic XML generation with Struts apps
> > >>>>
> > >>>>
> > >>>>This question may be a little off topic, but I think a good solution
> > >>>
> > > will
> > >
> > >>>be
> > >>>
> > >>>>of interest to the struts-user community so here goes...
> > >>>>
> > >>>>I have a number of pages in my app that display XML docs using
> > >>>
> > > XSL-like
> > >
> > >>>>transformations in the JSP (actually JSTL x: tags). I've implemented
> > >>>
> > >>>these
> > >>>
> > >>>>pages by using a prep-stage Action which dynamically creates the XML
> > >>>
> > > doc
> > >
> > >>>>from the database and places it in the session scope, then forwards
> to
> > >>>
> > >>>the
> > >>>
> > >>>>display JSP.
> > >>>>
> > >>>>It works great. But so far, I've been generating the XML laboriously
> > >>>
> > >>>using
> > >>>
> > >>>>DOM traversal and node creation calls hard coded into the Action. I
> > >>>
> > > have
> > >
> > >>>at
> > >>>
> > >>>>least a dozen such pages to generate and I don't relish the thought
> of
> > >>>
> > >>>doing
> > >>>
> > >>>>all of them in this hard-coded manner. What I'd like to do is create
> > >>>
> > > the
> > >
> > >>>XML
> > >>>
> > >>>>files declaratively, using an XML template that includes SQL calls,
> > >>>
> > > and
> > >
> > >>>>perhaps some references to a Map of run-time parameters.
> > >>>>
> > >>>>I looked at Doug Tidwell's article on the IBM site about doing
> > >>>>template-based XML generation, but it doesn't go far enough. (It does
> > >>>
> > > not
> > >
> > >>>>support such things as nested template specs for example.)
> > >>>>
> > >>>>So I started looking around. I found that Oracle has an XML SQL
> > >>>
> > > Utility
> > >
> > >>>>suite which appears to do much of what I'm after, but it only works
> > >>>
> > > for
> > >
> > >>>>Oracle.
> > >>>>
> > >>>>I also came across Jdbc2xml - a utility class from Intelligent
> Systems
> > >>>>Research, but the documentation is a bit sparse and I'm concerned
> that
> > >>>
> > > it
> > >
> > >>>>might not be very robust.
> > >>>>
> > >>>>Does anybody know of any other tools like this?
> > >>>>
> > >>>>Jefficus
> > >>>>
> > >>>>
> > >>>>---------------------------------------------------------------------
> > >>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >>>>
> > >>>>
> > >>>>
> > >>>>---------------------------------------------------------------------
> > >>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >>>>
> > >>>
> > >>>
> > >>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >>>
> > >>
> > >>
> > >>--
> > >>Kris Schneider <ma...@dotech.com>
> > >>D.O.Tech       <http://www.dotech.com/>
> > >>
> > >>---------------------------------------------------------------------
> > >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >>
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> > --
> > Kris Schneider <ma...@dotech.com>
> > D.O.Tech       <http://www.dotech.com/>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Integrating dynamic XML generation with Struts apps

Posted by Jeff Smith <je...@centralscheduling.net>.
Aah. Now I see what you are suggesting. (I think :-)

I don't think I provided enough detail in my problem description.

What I am trying to do is construct a document by drawing information from a
variety of tables and interleaving the results. And much of that structure
might be dependant on the actual data extracted.

Allow me to provide a simple example. I have a customer table with 10,000
customers, an invoice table with 50,000 invoices and an order-item table
with 200,000 individual order records. When Mr. Jones logs in, I want to
show him his most recent invoice/order.

So I need to construct an XML document on the fly that contains his customer
information, the ID of his most recent order and all the order-items that
are part of that order. With that document in scope, I can then render it
into a pretty display for him to view, using XSL:FO or CSS or whatever.

Your solution will work, but I think I either have to write a lot of
Action-time code to ensure that all the necessary table queries have been
executed and put into scope or else I have to write a lot of "code" in the
JSP. From my very lazy perspective, this is too much explicit coding and I'm
concerned that the resulting JSP file will be so laden with business logic
to construct the table information, that there is little hope of having a
graphic designer work the file to change the look.

What I'm looking for instead is a mechanism that lets me create a template
file like this:
<invoice sql="SELECT * FROM InvoiceTable WHERE InvID=$ParamOrderID">
    <customer sql="SELECT * FROM Customers WHERE CustID=$invoice.CustomerID>
        <name><SQLVALUE id="customer.Name"/></name>
        <phone><SQLVALUE id="customer.Phone"/></phone>
    </customer>
    <items sql="SELECT * FROM OrderTable WHERE OrderID=$ParamOrderID">
        <item>
        <itemname><SQLVALUE id="items.Name"></itemname>
        <quantity><SQLVALUE id="items.Number"></quantity>
        <price><SQLVALUE id="items.Cost"></itemnaem>
        </item>
    </items>
</invoice>

Loading this template and invoking it with Mr. Jones' order id provided as a
param would create this XML file:
<invoice>
    <customer>
        <name>Mr. Jones</name>
        <phone>555-1435</phone>
    </customer>
    <items>
        <item>
            <itemname>Widget</itemname>
            <quantity>50</quantity>
            <price>1.25</price>
        </item>
        <item>
            <itemname>Flanges</itemname>
            <quantity>120</quantity>
            <price>0.56</price>
        </item>
    </items>
</invoice>

This document would be extremely easy to render in my JSP, without confusing
the display with a lot of logic and sql calls and such.

I hope that's clearer.

Jefficus


----- Original Message -----
From: "Kris Schneider" <kr...@dotech.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, April 08, 2003 10:01 PM
Subject: Re: [OT] Integrating dynamic XML generation with Struts apps


> Yup, I got the part about the problem being the dynamic generation of the
XML.
> That's what the <c:forEach> element was supposed to address. I'm assuming
the
> XML you're currently generating as a DOM tree ends up looking something
like
> what Oracle's XML SQL Utility (XSU) outputs from a ResultSet:
>
> <ROWSET>
>    <ROW num="1">
>      <EMPNO>7369</EMPNO>
>      <ENAME>Smith</ENAME>
>      <JOB>CLERK</JOB>
>      <MGR>7902</MGR>
>      <HIREDATE>12/17/1980 0:0:0</HIREDATE>
>      <SAL>800</SAL>
>      <DEPTNO>20</DEPTNO>
>    </ROW>
>    <!-- additional rows ... -->
> </ROWSET>
>
> To do this dynamically, you can leverage a couple of JSTL utility
> classes/interfaces. If you've got a ResultSet, you can use:
>
> import javax.servlet.jsp.jstl.sql.Result;
> import javax.servlet.jsp.jstl.sql.ResultSupport;
> ...
> Result result = ResultSupport.toResult(resultSet);
> request.setAttribute("dbResult", result);
>
> Then, in a JSP, you can traverse dbResult:
>
> <rowset>
>    <%-- ${dbResult.rows} is a java.util.SortedMap[] --%>
>    <c:forEach var="rowMap" items="${dbResult.rows}" varStatus="rowNum">
>      <row num="<c:out value="${rowNum.count}"/>">
>        <c:forEach var="rowEntry" items="${rowMap}">
>          <c:set var="startTag"><<c:out value="${rowEntry.key}"/>></c:set>
>          <c:set var="endTag"></<c:out value="${rowEntry.key}"/>></c:set>
>          <c:out value="${startTag}" escapeXml="false"/>
>            <c:out value="${rowEntry.value}"/>
>          <c:out value="${endTag}" escapeXml="false"/>
>        </c:forEach>
>      </row>
>    </c:forEach>
> </rowset>
>
> Admittedly, I haven't tried the constructs for "startTag" and "endTag",
but
> something like it ought to be doable ;-). You might also be able to
accomplish
> something similar by using org.apache.commons.beanutils.RowSetDynaClass
instead
> of JSTL's Result.
>
> I'm not sure I understand what you mean by "batch", and I certainly don't
know
> what your requirements are for integrating with other logic tags, but the
> <x:transform> tag is pretty flexible. The value of its "xslt" attribute
can be a
> String, Reader, or javax.xml.transform.Source. You can also capture the
result
> of the transformation by using either the "var" attribute to export a DOM
> document, or the "result" attribute to use an existing
javax.xml.transform.Result.
>
> Jeff Smith wrote:
> > My problem is not in how to transform the XML doc for display. The
problem
> > is dynamically generating the XML in the first place - from data fields
held
> > in my db.
> >
> > Once I've got the XML file, the display-time transformations can be done
in
> > dozens of different ways. I actually do something not unlike your
> > suggestion. However, I can't use a "batch" style sheet as you've
sketched,
> > because I need to integrate the transformation with other run-time logic
> > tags.
> >
> > Jefficus
> >
> > ----- Original Message -----
> > From: "Kris Schneider" <kr...@dotech.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Tuesday, April 08, 2003 2:00 PM
> > Subject: Re: [OT] Integrating dynamic XML generation with Struts apps
> >
> >
> >
> >>If you're already using JSTL, why not use JSP to create *and* transform
> >
> > the XML:
> >
> >><x:transform xslt="${stylesheet}">
> >>  <%-- body specifies dynamic XML document and transform params --%>
> >>  <c:forEach var="row" items="${dataCollection}">
> >>    <row>
> >>      ...
> >>    </row>
> >>  </c:forEach>
> >></x:transform>
> >>
> >>Quoting Jeff Smith <je...@centralscheduling.net>:
> >>
> >>
> >>>I've looked briefly at Cocoon. It appears to be massively overkill for
> >>
> > my
> >
> >>>rather simple needs. Although if somebody out there is using it to
> >>
> > simply
> >
> >>>create dynamic XML to feed a struts app, I'd love to hear about your
> >>>experiences.
> >>>
> >>>Jefficus
> >>>
> >>>----- Original Message -----
> >>>From: "Mike Jasnowski" <mj...@bea.com>
> >>>
> >>>
> >>>>Not sure if this is what you're after exaclt, but have you looked at
> >>>
> >>>Cocoon?
> >>>
> >>>>-----Original Message-----
> >>>>From: Jeff Smith [mailto:jeffs@centralscheduling.net]
> >>>>Sent: Tuesday, April 08, 2003 2:56 PM
> >>>>To: Struts Users Mailing List
> >>>>Subject: [OT] Integrating dynamic XML generation with Struts apps
> >>>>
> >>>>
> >>>>This question may be a little off topic, but I think a good solution
> >>>
> > will
> >
> >>>be
> >>>
> >>>>of interest to the struts-user community so here goes...
> >>>>
> >>>>I have a number of pages in my app that display XML docs using
> >>>
> > XSL-like
> >
> >>>>transformations in the JSP (actually JSTL x: tags). I've implemented
> >>>
> >>>these
> >>>
> >>>>pages by using a prep-stage Action which dynamically creates the XML
> >>>
> > doc
> >
> >>>>from the database and places it in the session scope, then forwards to
> >>>
> >>>the
> >>>
> >>>>display JSP.
> >>>>
> >>>>It works great. But so far, I've been generating the XML laboriously
> >>>
> >>>using
> >>>
> >>>>DOM traversal and node creation calls hard coded into the Action. I
> >>>
> > have
> >
> >>>at
> >>>
> >>>>least a dozen such pages to generate and I don't relish the thought of
> >>>
> >>>doing
> >>>
> >>>>all of them in this hard-coded manner. What I'd like to do is create
> >>>
> > the
> >
> >>>XML
> >>>
> >>>>files declaratively, using an XML template that includes SQL calls,
> >>>
> > and
> >
> >>>>perhaps some references to a Map of run-time parameters.
> >>>>
> >>>>I looked at Doug Tidwell's article on the IBM site about doing
> >>>>template-based XML generation, but it doesn't go far enough. (It does
> >>>
> > not
> >
> >>>>support such things as nested template specs for example.)
> >>>>
> >>>>So I started looking around. I found that Oracle has an XML SQL
> >>>
> > Utility
> >
> >>>>suite which appears to do much of what I'm after, but it only works
> >>>
> > for
> >
> >>>>Oracle.
> >>>>
> >>>>I also came across Jdbc2xml - a utility class from Intelligent Systems
> >>>>Research, but the documentation is a bit sparse and I'm concerned that
> >>>
> > it
> >
> >>>>might not be very robust.
> >>>>
> >>>>Does anybody know of any other tools like this?
> >>>>
> >>>>Jefficus
> >>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>>>
> >>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>>>
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>>
> >>
> >>
> >>--
> >>Kris Schneider <ma...@dotech.com>
> >>D.O.Tech       <http://www.dotech.com/>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Integrating dynamic XML generation with Struts apps

Posted by Kris Schneider <kr...@dotech.com>.
Yup, I got the part about the problem being the dynamic generation of the XML. 
That's what the <c:forEach> element was supposed to address. I'm assuming the 
XML you're currently generating as a DOM tree ends up looking something like 
what Oracle's XML SQL Utility (XSU) outputs from a ResultSet:

<ROWSET>
   <ROW num="1">
     <EMPNO>7369</EMPNO>
     <ENAME>Smith</ENAME>
     <JOB>CLERK</JOB>
     <MGR>7902</MGR>
     <HIREDATE>12/17/1980 0:0:0</HIREDATE>
     <SAL>800</SAL>
     <DEPTNO>20</DEPTNO>
   </ROW>
   <!-- additional rows ... -->
</ROWSET>

To do this dynamically, you can leverage a couple of JSTL utility 
classes/interfaces. If you've got a ResultSet, you can use:

import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.ResultSupport;
...
Result result = ResultSupport.toResult(resultSet);
request.setAttribute("dbResult", result);

Then, in a JSP, you can traverse dbResult:

<rowset>
   <%-- ${dbResult.rows} is a java.util.SortedMap[] --%>
   <c:forEach var="rowMap" items="${dbResult.rows}" varStatus="rowNum">
     <row num="<c:out value="${rowNum.count}"/>">
       <c:forEach var="rowEntry" items="${rowMap}">
         <c:set var="startTag"><<c:out value="${rowEntry.key}"/>></c:set>
         <c:set var="endTag"></<c:out value="${rowEntry.key}"/>></c:set>
         <c:out value="${startTag}" escapeXml="false"/>
           <c:out value="${rowEntry.value}"/>
         <c:out value="${endTag}" escapeXml="false"/>
       </c:forEach>
     </row>
   </c:forEach>
</rowset>

Admittedly, I haven't tried the constructs for "startTag" and "endTag", but 
something like it ought to be doable ;-). You might also be able to accomplish 
something similar by using org.apache.commons.beanutils.RowSetDynaClass instead 
of JSTL's Result.

I'm not sure I understand what you mean by "batch", and I certainly don't know 
what your requirements are for integrating with other logic tags, but the 
<x:transform> tag is pretty flexible. The value of its "xslt" attribute can be a 
String, Reader, or javax.xml.transform.Source. You can also capture the result 
of the transformation by using either the "var" attribute to export a DOM 
document, or the "result" attribute to use an existing javax.xml.transform.Result.

Jeff Smith wrote:
> My problem is not in how to transform the XML doc for display. The problem
> is dynamically generating the XML in the first place - from data fields held
> in my db.
> 
> Once I've got the XML file, the display-time transformations can be done in
> dozens of different ways. I actually do something not unlike your
> suggestion. However, I can't use a "batch" style sheet as you've sketched,
> because I need to integrate the transformation with other run-time logic
> tags.
> 
> Jefficus
> 
> ----- Original Message -----
> From: "Kris Schneider" <kr...@dotech.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Tuesday, April 08, 2003 2:00 PM
> Subject: Re: [OT] Integrating dynamic XML generation with Struts apps
> 
> 
> 
>>If you're already using JSTL, why not use JSP to create *and* transform
> 
> the XML:
> 
>><x:transform xslt="${stylesheet}">
>>  <%-- body specifies dynamic XML document and transform params --%>
>>  <c:forEach var="row" items="${dataCollection}">
>>    <row>
>>      ...
>>    </row>
>>  </c:forEach>
>></x:transform>
>>
>>Quoting Jeff Smith <je...@centralscheduling.net>:
>>
>>
>>>I've looked briefly at Cocoon. It appears to be massively overkill for
>>
> my
> 
>>>rather simple needs. Although if somebody out there is using it to
>>
> simply
> 
>>>create dynamic XML to feed a struts app, I'd love to hear about your
>>>experiences.
>>>
>>>Jefficus
>>>
>>>----- Original Message -----
>>>From: "Mike Jasnowski" <mj...@bea.com>
>>>
>>>
>>>>Not sure if this is what you're after exaclt, but have you looked at
>>>
>>>Cocoon?
>>>
>>>>-----Original Message-----
>>>>From: Jeff Smith [mailto:jeffs@centralscheduling.net]
>>>>Sent: Tuesday, April 08, 2003 2:56 PM
>>>>To: Struts Users Mailing List
>>>>Subject: [OT] Integrating dynamic XML generation with Struts apps
>>>>
>>>>
>>>>This question may be a little off topic, but I think a good solution
>>>
> will
> 
>>>be
>>>
>>>>of interest to the struts-user community so here goes...
>>>>
>>>>I have a number of pages in my app that display XML docs using
>>>
> XSL-like
> 
>>>>transformations in the JSP (actually JSTL x: tags). I've implemented
>>>
>>>these
>>>
>>>>pages by using a prep-stage Action which dynamically creates the XML
>>>
> doc
> 
>>>>from the database and places it in the session scope, then forwards to
>>>
>>>the
>>>
>>>>display JSP.
>>>>
>>>>It works great. But so far, I've been generating the XML laboriously
>>>
>>>using
>>>
>>>>DOM traversal and node creation calls hard coded into the Action. I
>>>
> have
> 
>>>at
>>>
>>>>least a dozen such pages to generate and I don't relish the thought of
>>>
>>>doing
>>>
>>>>all of them in this hard-coded manner. What I'd like to do is create
>>>
> the
> 
>>>XML
>>>
>>>>files declaratively, using an XML template that includes SQL calls,
>>>
> and
> 
>>>>perhaps some references to a Map of run-time parameters.
>>>>
>>>>I looked at Doug Tidwell's article on the IBM site about doing
>>>>template-based XML generation, but it doesn't go far enough. (It does
>>>
> not
> 
>>>>support such things as nested template specs for example.)
>>>>
>>>>So I started looking around. I found that Oracle has an XML SQL
>>>
> Utility
> 
>>>>suite which appears to do much of what I'm after, but it only works
>>>
> for
> 
>>>>Oracle.
>>>>
>>>>I also came across Jdbc2xml - a utility class from Intelligent Systems
>>>>Research, but the documentation is a bit sparse and I'm concerned that
>>>
> it
> 
>>>>might not be very robust.
>>>>
>>>>Does anybody know of any other tools like this?
>>>>
>>>>Jefficus
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>
>>
>>--
>>Kris Schneider <ma...@dotech.com>
>>D.O.Tech       <http://www.dotech.com/>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Integrating dynamic XML generation with Struts apps

Posted by Jeff Smith <je...@centralscheduling.net>.
My problem is not in how to transform the XML doc for display. The problem
is dynamically generating the XML in the first place - from data fields held
in my db.

Once I've got the XML file, the display-time transformations can be done in
dozens of different ways. I actually do something not unlike your
suggestion. However, I can't use a "batch" style sheet as you've sketched,
because I need to integrate the transformation with other run-time logic
tags.

Jefficus

----- Original Message -----
From: "Kris Schneider" <kr...@dotech.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, April 08, 2003 2:00 PM
Subject: Re: [OT] Integrating dynamic XML generation with Struts apps


> If you're already using JSTL, why not use JSP to create *and* transform
the XML:
>
> <x:transform xslt="${stylesheet}">
>   <%-- body specifies dynamic XML document and transform params --%>
>   <c:forEach var="row" items="${dataCollection}">
>     <row>
>       ...
>     </row>
>   </c:forEach>
> </x:transform>
>
> Quoting Jeff Smith <je...@centralscheduling.net>:
>
> > I've looked briefly at Cocoon. It appears to be massively overkill for
my
> > rather simple needs. Although if somebody out there is using it to
simply
> > create dynamic XML to feed a struts app, I'd love to hear about your
> > experiences.
> >
> > Jefficus
> >
> > ----- Original Message -----
> > From: "Mike Jasnowski" <mj...@bea.com>
> >
> >
> > > Not sure if this is what you're after exaclt, but have you looked at
> > Cocoon?
> > >
> > > -----Original Message-----
> > > From: Jeff Smith [mailto:jeffs@centralscheduling.net]
> > > Sent: Tuesday, April 08, 2003 2:56 PM
> > > To: Struts Users Mailing List
> > > Subject: [OT] Integrating dynamic XML generation with Struts apps
> > >
> > >
> > > This question may be a little off topic, but I think a good solution
will
> > be
> > > of interest to the struts-user community so here goes...
> > >
> > > I have a number of pages in my app that display XML docs using
XSL-like
> > > transformations in the JSP (actually JSTL x: tags). I've implemented
> > these
> > > pages by using a prep-stage Action which dynamically creates the XML
doc
> > > from the database and places it in the session scope, then forwards to
> > the
> > > display JSP.
> > >
> > > It works great. But so far, I've been generating the XML laboriously
> > using
> > > DOM traversal and node creation calls hard coded into the Action. I
have
> > at
> > > least a dozen such pages to generate and I don't relish the thought of
> > doing
> > > all of them in this hard-coded manner. What I'd like to do is create
the
> > XML
> > > files declaratively, using an XML template that includes SQL calls,
and
> > > perhaps some references to a Map of run-time parameters.
> > >
> > > I looked at Doug Tidwell's article on the IBM site about doing
> > > template-based XML generation, but it doesn't go far enough. (It does
not
> > > support such things as nested template specs for example.)
> > >
> > > So I started looking around. I found that Oracle has an XML SQL
Utility
> > > suite which appears to do much of what I'm after, but it only works
for
> > > Oracle.
> > >
> > > I also came across Jdbc2xml - a utility class from Intelligent Systems
> > > Research, but the documentation is a bit sparse and I'm concerned that
it
> > > might not be very robust.
> > >
> > > Does anybody know of any other tools like this?
> > >
> > > Jefficus
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Integrating dynamic XML generation with Struts apps

Posted by Kris Schneider <kr...@dotech.com>.
If you're already using JSTL, why not use JSP to create *and* transform the XML:

<x:transform xslt="${stylesheet}">
  <%-- body specifies dynamic XML document and transform params --%>
  <c:forEach var="row" items="${dataCollection}">
    <row>
      ...
    </row>
  </c:forEach>
</x:transform>

Quoting Jeff Smith <je...@centralscheduling.net>:

> I've looked briefly at Cocoon. It appears to be massively overkill for my
> rather simple needs. Although if somebody out there is using it to simply
> create dynamic XML to feed a struts app, I'd love to hear about your
> experiences.
> 
> Jefficus
> 
> ----- Original Message -----
> From: "Mike Jasnowski" <mj...@bea.com>
> 
> 
> > Not sure if this is what you're after exaclt, but have you looked at
> Cocoon?
> >
> > -----Original Message-----
> > From: Jeff Smith [mailto:jeffs@centralscheduling.net]
> > Sent: Tuesday, April 08, 2003 2:56 PM
> > To: Struts Users Mailing List
> > Subject: [OT] Integrating dynamic XML generation with Struts apps
> >
> >
> > This question may be a little off topic, but I think a good solution will
> be
> > of interest to the struts-user community so here goes...
> >
> > I have a number of pages in my app that display XML docs using XSL-like
> > transformations in the JSP (actually JSTL x: tags). I've implemented
> these
> > pages by using a prep-stage Action which dynamically creates the XML doc
> > from the database and places it in the session scope, then forwards to
> the
> > display JSP.
> >
> > It works great. But so far, I've been generating the XML laboriously
> using
> > DOM traversal and node creation calls hard coded into the Action. I have
> at
> > least a dozen such pages to generate and I don't relish the thought of
> doing
> > all of them in this hard-coded manner. What I'd like to do is create the
> XML
> > files declaratively, using an XML template that includes SQL calls, and
> > perhaps some references to a Map of run-time parameters.
> >
> > I looked at Doug Tidwell's article on the IBM site about doing
> > template-based XML generation, but it doesn't go far enough. (It does not
> > support such things as nested template specs for example.)
> >
> > So I started looking around. I found that Oracle has an XML SQL Utility
> > suite which appears to do much of what I'm after, but it only works for
> > Oracle.
> >
> > I also came across Jdbc2xml - a utility class from Intelligent Systems
> > Research, but the documentation is a bit sparse and I'm concerned that it
> > might not be very robust.
> >
> > Does anybody know of any other tools like this?
> >
> > Jefficus
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Integrating dynamic XML generation with Struts apps

Posted by Jeff Smith <je...@centralscheduling.net>.
I've looked briefly at Cocoon. It appears to be massively overkill for my
rather simple needs. Although if somebody out there is using it to simply
create dynamic XML to feed a struts app, I'd love to hear about your
experiences.

Jefficus

----- Original Message -----
From: "Mike Jasnowski" <mj...@bea.com>


> Not sure if this is what you're after exaclt, but have you looked at
Cocoon?
>
> -----Original Message-----
> From: Jeff Smith [mailto:jeffs@centralscheduling.net]
> Sent: Tuesday, April 08, 2003 2:56 PM
> To: Struts Users Mailing List
> Subject: [OT] Integrating dynamic XML generation with Struts apps
>
>
> This question may be a little off topic, but I think a good solution will
be
> of interest to the struts-user community so here goes...
>
> I have a number of pages in my app that display XML docs using XSL-like
> transformations in the JSP (actually JSTL x: tags). I've implemented these
> pages by using a prep-stage Action which dynamically creates the XML doc
> from the database and places it in the session scope, then forwards to the
> display JSP.
>
> It works great. But so far, I've been generating the XML laboriously using
> DOM traversal and node creation calls hard coded into the Action. I have
at
> least a dozen such pages to generate and I don't relish the thought of
doing
> all of them in this hard-coded manner. What I'd like to do is create the
XML
> files declaratively, using an XML template that includes SQL calls, and
> perhaps some references to a Map of run-time parameters.
>
> I looked at Doug Tidwell's article on the IBM site about doing
> template-based XML generation, but it doesn't go far enough. (It does not
> support such things as nested template specs for example.)
>
> So I started looking around. I found that Oracle has an XML SQL Utility
> suite which appears to do much of what I'm after, but it only works for
> Oracle.
>
> I also came across Jdbc2xml - a utility class from Intelligent Systems
> Research, but the documentation is a bit sparse and I'm concerned that it
> might not be very robust.
>
> Does anybody know of any other tools like this?
>
> Jefficus
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] Integrating dynamic XML generation with Struts apps

Posted by Mike Jasnowski <mj...@bea.com>.
Not sure if this is what you're after exaclt, but have you looked at Cocoon?

-----Original Message-----
From: Jeff Smith [mailto:jeffs@centralscheduling.net]
Sent: Tuesday, April 08, 2003 2:56 PM
To: Struts Users Mailing List
Subject: [OT] Integrating dynamic XML generation with Struts apps


This question may be a little off topic, but I think a good solution will be
of interest to the struts-user community so here goes...

I have a number of pages in my app that display XML docs using XSL-like
transformations in the JSP (actually JSTL x: tags). I've implemented these
pages by using a prep-stage Action which dynamically creates the XML doc
from the database and places it in the session scope, then forwards to the
display JSP.

It works great. But so far, I've been generating the XML laboriously using
DOM traversal and node creation calls hard coded into the Action. I have at
least a dozen such pages to generate and I don't relish the thought of doing
all of them in this hard-coded manner. What I'd like to do is create the XML
files declaratively, using an XML template that includes SQL calls, and
perhaps some references to a Map of run-time parameters.

I looked at Doug Tidwell's article on the IBM site about doing
template-based XML generation, but it doesn't go far enough. (It does not
support such things as nested template specs for example.)

So I started looking around. I found that Oracle has an XML SQL Utility
suite which appears to do much of what I'm after, but it only works for
Oracle.

I also came across Jdbc2xml - a utility class from Intelligent Systems
Research, but the documentation is a bit sparse and I'm concerned that it
might not be very robust.

Does anybody know of any other tools like this?

Jefficus


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org