You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by David Goodenough <da...@btconnect.com> on 2004/06/02 18:18:43 UTC

xml and date problem

I have a problem with either xml parsing or date formatting, I am not quite
sure which.

Consider the following code:-

<x:parse var="xml">
  <test>
    <unit date="20040602142014">
      </unit>
    <unit date="20040602143809">
      </unit>
    </test>
  </x:parse>
<table>
  <x:forEach select="$xml/test/unit">
    <fmt:parseDate var="updated" pattern="yyyyMMddHHmmss" type="both">
      <x:out select="@date" />
      </fmt:parseDate>
      <TR>
        <TD>
          <fmt:formatDate value="${updated}" pattern="yyyy-MM-dd HH:mm:ss" />
          </TD>
        </TR>
    </x:forEach>
  </TABLE>

One would expect this to produce:-

2004-06-02 14:20:14
2004-06-02 14:38:09

but instead it produces:-

2004-06-02 14:20:14
2004-06-02 14:20:14

i.e. it repeats the first date.  If there are more than two xml items it 
repeats the same date all the way through.

Is this a known problem, and is there a fix?

David

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


Re: xml and date problem

Posted by Kris Schneider <kr...@dotech.com>.
I changed your example only to make it work more nicely as text output:

<%@ page contentType="text/plain" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="x"   uri="http://java.sun.com/jstl/xml" %>

<x:parse var="xml">
<test>
    <unit date="20040602142014">
    </unit>
    <unit date="20040602143809">
    </unit>
</test>
</x:parse>

<x:forEach select="$xml/test/unit">
    <fmt:parseDate var="updated" pattern="yyyyMMddHHmmss" type="both">
        <x:out select="@date" />
    </fmt:parseDate>
    <fmt:formatDate value="${updated}" pattern="yyyy-MM-dd HH:mm:ss" />
</x:forEach>

And got:

2004-06-02 14:20:14
2004-06-02 14:38:09

So what's the problem? ;-) I used TC 5.0.24 (running in Servlet 2.3/JSP 1.2
mode) with Xerces 2.6.2 and Xalan 2.6.0 installed in common/endorsed. Try
upgrading Xerces and Xalan.

Quoting David Goodenough <da...@btconnect.com>:

> I have a problem with either xml parsing or date formatting, I am not quite
> sure which.
> 
> Consider the following code:-
> 
> <x:parse var="xml">
>   <test>
>     <unit date="20040602142014">
>       </unit>
>     <unit date="20040602143809">
>       </unit>
>     </test>
>   </x:parse>
> <table>
>   <x:forEach select="$xml/test/unit">
>     <fmt:parseDate var="updated" pattern="yyyyMMddHHmmss" type="both">
>       <x:out select="@date" />
>       </fmt:parseDate>
>       <TR>
>         <TD>
>           <fmt:formatDate value="${updated}" pattern="yyyy-MM-dd HH:mm:ss"
> />
>           </TD>
>         </TR>
>     </x:forEach>
>   </TABLE>
> 
> One would expect this to produce:-
> 
> 2004-06-02 14:20:14
> 2004-06-02 14:38:09
> 
> but instead it produces:-
> 
> 2004-06-02 14:20:14
> 2004-06-02 14:20:14
> 
> i.e. it repeats the first date.  If there are more than two xml items it 
> repeats the same date all the way through.
> 
> Is this a known problem, and is there a fix?
> 
> David

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

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