[Templates] FOREACH enhancement request

Dave Howorth dhoworth@mrc-lmb.cam.ac.uk
Thu, 02 Oct 2003 15:45:29 +0100


robbin.bonthond@philips.com wrote:
> I am using TT2 v2.10, and I am having problems with my loops.
and
 >I am importing a XML file with XML::Mini

It looks to me that the problem is an inconsistency in the behaviour of 
XML::Mini, rather than TT.

If there's more than one book (more than one element in an XML sequence) 
you get an array:

> my $config={
>     books => {
>         book => [
>             { title => "title1" },
>             { title => "title2" },
>         ]
>     }
> };

but if there's only one element in the XML sequence, Mini::XML chooses a 
different representation.

> my $config={
>     books => {
>         book => { title => "title" },
>     }
> };

Or have I misundertood something?  Perhaps there's a hint on 
<http://minixml.psychogenic.com/>

"MiniXML is not interested in DTDs and will therefore not validate XML 
against a Document Type Definition"

So it doesn't have enough information to know that a book should be 
represented as a sequence of one books.

Perhaps there's another way of accessing the parsed file from XML::Mini 
that *will* produce a consistent data structure.  Or another option 
might be to consider switching to XML::LibXML or another library.

Cheers, Dave