According to the
CREATING XML DATAsection, this is the expected behavior.
So something closer to what you are looking for is this:
use strict;
use XML::Smart;
my $job_name = "a job name";
my $desc = "a description";
my $desc2 = "another description";
my $num = "a number";
my $XML = XML::Smart->new();
$XML->{JOB}{NAME}[0] = $job_name;
$XML->{JOB}{DESC}[0] = $desc;
$XML->{JOB}{DESC}[1] = $desc2;
$XML->{JOB}{NUM}[0] = $num;
$XML->save('output.xml');
Which produces:
<JOB NAME="a job name" NUM="a number">
<DESC>a description</DESC>
<DESC>another description</DESC>
</JOB>
So the presence of multiple entries is what makes it a nested element. If this behavior is not what you desire, perhaps
XML::Twig or
XML::libXML would better work for you. I have got great results from libXML in the past.
Update:
I checked the
tutorial and found what you're looking for.
$XML->{JOB}{DESC}= $desc;
$XML->{JOB}{DESC}->set_node(1) ;
This code will nest the description as an element.
Results:
<JOB NAME="a job name" NUM="a number">
<DESC>a description</DESC>
</JOB>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.