All --

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:

[%- 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) %]

All this will print out is ":"

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.