Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I might not be on the same page here - XML for a database? Maybe XML instead of a database ...

Consider making a FAQ: there is a very generic layout for a FAQ. My idea was to use an HTML::Template template file to describe the layout, and use an XML file to contain the content. Sure i could have used a database, but then i would have to write some sort of a front end to enter in the data - why not use XML to wrap my data instead? It seemed easier to me.

Here is a stripped down version - it is not perfect and could probably use a revision, but it should be enough to demonstrate. As a matter of fact, i hear that you can even bypass having to use Perl to translate the XML directly to HTML - i'll hopefully learn more about that when my copy of Perl and XML arrives in the mail. (update - doh! i already knew about that - XSLT ;) - and so far that book is some very good reading)

There are a total of three files - save them with the suggested names and run the .pl file to generate the final HTML. You can redirect the output to an .html file, or even modify the script to be a CGI script instead.

<ol> <tmpl_loop name="category"> <li><a href="#<tmpl_var name=anchor>"><tmpl_var name="type"></a> <ol> <tmpl_loop name="qa_pair"> <li><tmpl_var name="question"> </tmpl_loop> </ol> </tmpl_loop> </ol> <p><hr/></p> <tmpl_loop name="category"> <a name="<tmpl_var name=anchor>"><h3><tmpl_var name="type"></h3></a> <tmpl_loop name="qa_pair"> <h4><tmpl_var name="question"></h4> <p><tmpl_var name="answer"></p> </tmpl_loop> <hr/> </tmpl_loop>
<xml> <category type="Generic Stuff"> <qa_pair> <question>How do I do stuff?</question> <answer> Just do it. Stuff is best done by doing it. By not doing it, stuff doesn't happen. </answer> </qa_pair> <qa_pair> <question>What do I do with this stuff?</question> <answer> Stuff. You do stuff with stuff. That way the stuff is used. </answer> </qa_pair> </category> <category type="Specific Stuff"> <qa_pair> <question>Do I really have to do stuff?</question> <answer> Of course not, you can just sit there without doing anything. Well you do have to breathe and eat and use Data::Dumper here and there. Stuff is good. Don't be afraid of stuff. </answer> </qa_pair> <qa_pair> <question>My girlfriend says stuff. Should we break up?</question> <answer> Of course not. It is common for a spouse to say stuff, you should encourage them and stuff. </answer> </qa_pair> </category> </xml>
use strict; use HTML::Template; use XML::Simple; my $xml = XMLin('./faq.xml') or die $!; my $template = HTML::Template->new( filename => 'faq.tmpl', die_on_bad_params => 0, ); # this could definitely use some refactoring - oh well ;) foreach my $cat (@{$xml->{'category'}}) { $cat->{'anchor'} = $cat->{'type'}; $cat->{'anchor'} =~ s/ /_/g; $cat->{'anchor'} =~ s/[^\w]//g; } $template->param( category => $xml->{'category'}, ); print $template->output();
You can see the real deal at

Hope this is on topic ...


(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: XML for databases?!?! Is it just me or is the rest of the world nutz? by jeffa
in thread XML for databases?!?! Is it just me or is the rest of the world nutz? by S_Shrum

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [shmem]: LanX: uhm, that looks like work to be done for me.
    shmem frowns at LanX for being stirred out of laziness

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (9)
    As of 2017-04-27 19:10 GMT
    Find Nodes?
      Voting Booth?
      I'm a fool:

      Results (512 votes). Check out past polls.