Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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>

In reply to Re^3: How do you create sub-nodes with XML::Smart by ramrod
in thread How do you create sub-nodes with XML::Smart by Anonymous Monk

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
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (10)
    As of 2020-12-03 19:01 GMT
    Find Nodes?
      Voting Booth?
      How often do you use taint mode?

      Results (57 votes). Check out past polls.