Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: How do you create sub-nodes with XML::Smart

by Anonymous Monk
on Mar 03, 2009 at 19:34 UTC ( #747864=note: print w/replies, xml ) Need Help??

in reply to Re: How do you create sub-nodes with XML::Smart
in thread How do you create sub-nodes with XML::Smart

Duly noted on the code tags. I did try the code you posted but it still have me this output:
$XML->{JOB}{NAME} = $job_name; $XML->{JOB}{DESC}[0] = $desc; $XML->{JOB}{DATA}[0] = $data; $XML->{JOB}{WHO}[0] = $who; <JOB NAME="Jonname" DESC="Description" DATA="Data..."/>
I would have thought that it would have given me something like this:
<JOB NAME="Name"> <DESC>Description</DESC> <DATA>Data</DATA> ...... </JOB>
...but it did not. Any other ideas? I have definitely looked over the CPAN site and I didn't see anything that answered my question. Thanks!

Replies are listed 'Best First'.
Re^3: How do you create sub-nodes with XML::Smart
by ramrod (Curate) on Mar 03, 2009 at 20:58 UTC
    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>
      That worked beautifully. I appreciate the help!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://747864]
[shmem]: Discipulus: well, a node with just one glaring truth on it is most easily upvoted ;-)
[Discipulus]: i'd like to be the vote fairy just one month.. ;=)
[choroba]: My average XP per node lowered in the last three months :(
[choroba]: (check my homenode for the graph link and the tool to create it)

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-04-26 11:58 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (474 votes). Check out past polls.