Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi. I'm not sure I understand what is so complex about your scenario. Perhaps you can provide more exact details about your input and output in your real-life scenario, and then we'd have some common ground to go on.

To get your output, you can easily modify the code I gave you:

# file test.pl use HTML::Template; use strict; use warnings; my $template = HTML::Template->new(filename => 'test.tmpl'); # params $template->param(tag1_common => 'XXX'); $template->param(tag2_common => 'YYY'); $template->param(tag3_common => 'ZZZ'); print $template->output(); # file test.tmpl <root> <tag1> <commontag><TMPL_VAR ESCAPE=HTML tag1_common></commontag> </tag1> <tag2> <commontag><TMPL_VAR ESCAPE=HTML tag2_common></commontag> </tag2> <tag3> <commontag><TMPL_VAR ESCAPE=HTML tag3_common></commontag> </tag3> </root> # output <root> <tag1> <commontag>XXX</commontag> </tag1> <tag2> <commontag>YYY</commontag> </tag2> <tag3> <commontag>ZZZ</commontag> </tag3> </root>

But perhaps what you're really asking about is the ability to have loops in your template. Well, if you would read the docs, you'd find you can do that too! Perhaps you're looking for something along these lines:

# file test.pl use HTML::Template; use strict; use warnings; my $template = HTML::Template->new(filename => 'test.tmpl'); my @xml = ( { parent => 'tag1', common_value => 'XXX', }, { parent => 'tag2', common_value => 'YYY', }, { parent => 'tag3', common_value => 'XXX', }, ); # params $template->param( loop => \@xml ); print $template->output(); # file test.tmpl <root> <TMPL_LOOP loop> <<TMPL_VAR parent>> <commontag><TMPL_VAR ESCAPE=HTML common_value></commontag> </<TMPL_VAR parent>> </TMPL_LOOP> </root> # output <root> <tag1> <commontag>XXX</commontag> </tag1> <tag2> <commontag>YYY</commontag> </tag2> <tag3> <commontag>XXX</commontag> </tag3> </root>

Again, I'm just guessing here, since you're not providing enough detail about your actual needs.

--
edan


In reply to Re^3: Generating XML from a template by edan
in thread Generating XML from a template by piyush.shourie

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (9)
    As of 2014-09-15 04:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (145 votes), past polls