I agree that it's simple thing to produce without using dedicated XML tools, but the character reservations that are involved with XML makes it potentially dangerous to do so. If you're willing to test, capture, and replace the characters (the minimum you should be doing is
&,
<,
>, and
%) in the data you're managing, that's fine, but the modules button all of that up for you nicely.
Here's how I'd do that. It's more code, granted, but it's always valid. Given the quality of some of the other tools that I've had to use that require XML, this will give me the best shot at not having to mess with it after I have it in production.
use strict;
use warnings;
use XML::Twig;
my $stream_id = 'stream-id';
my $event_name = 'event-name';
my $time_t = 'time-t';
my $filename = 'foo.xml';
my $twig = XML::Twig->new(pretty_print => 'record');
$twig->parse('<event/>');
my $root = $twig->root();
$root->insert_new_elt('stream-id' => $stream_id);
my $event_tag = $root->insert_new_elt('event-name' => $event_name);
my $primary_event_tag = $event_tag->insert_new_elt('primary-event');
$primary_event_tag->insert_new_elt('delete-time' => $time_t);
open(my $FH, '>', $filename);
$twig->flush(\*$FH);
close $FH;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.