I just started Perl last week kinda as a test for this project, so my syntax isn't the greatest -- not too mention I am forced to switch between .Net, C++, Java, and VBScript while doing it.
Basically the task is to test the speed at which Perl & Template Toolkit can parse the data. I've been somewhat successful with XML::Simple, but I'm lacking the idea on how to tell if there are any more nodes left.
The basic XML is:
<prices> <section name="blah"> <open>5</open> <ttype name="kid" price="50.00" /> <ttype ...> </section> </prices>
Using the following Perl, I call the template toolkit, using ActivePerl 5.8 on Win2K.
use strict; use Template; my $tt = Template->new(); $tt->process('config.tt', {}) or die $tt->error();
The toolkit template is what's messing me up.. I've originally done
[%- USE xml = XML.Simple('config.xml') %] [%- FOREACH a = xml.keys() %] [% a %]: [%- FOREACH b = xml.$a.keys() %] [% b %] [%- END %] [%- END %] [%- END %]
and so on... this was simply to dump the data to the screen in order to test the speed. However, the XML can change in depth, and I can't (or more accurately, don't know how) to test if the node has keys or not.
From what I've read, XML::Simple may not be the fastest way (I believe it uses SAX?) and am also trying to use the DOM -- albeit all through Template Toolkit -- of which there are very little examples. Additionally, it tends to ignore the ones with more than one attribute, so I figure try the DOM. Here's what I've tried in XML::Dom to no avail:
All this will print out is ":"[%- USE xml = XML.DOM %] [% dom = xml.parse( 'config.xml' ) %] [% FOREACH product = dom.getElementsByTagName('price') %] [% product.getAttribute('ttype') %]: [% VIEW ttype%] [% BLOCK product %] [% item.content(view) %] [% END %] [%- END %] [%-END%] [% #USE Dumper %] [%# Dumper.dump(xml) %]
Before I give up, I figure I'd try it here.. .someone in the company told me to use XML::PerlSAX module, but I've seen a few reviews that says it's buggy at best.
Now, I guess the question is, how do I get the XML to parse inside the template toolkit template? It seems like it should be simple enough, but I can't quite get it going, or it only works 3/4ths of the way.
Thanks --
DesertGhost
In reply to Template Toolkit and XML by DesertGhost
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |