Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: XMLout and keys/attributes

by sauoq (Abbot)
on May 09, 2012 at 15:02 UTC ( #969643=note: print w/replies, xml ) Need Help??

in reply to XMLout and keys/attributes

Remove the ContentKey option from your call to XMLout and change where you set $XmlRef to the following:

$XmlRef->{$keyname}{'devices'}{'dev'.$cnt}{'param'} = [ {$foo => $userref->{$key}{'hash'}{$foo}} ];
Update: No, that's not right... you have two tags, so you have to push them on... Try this:
$XmlRef->{$keyname}{'devices'}{'dev'.$cnt}{'param'} = []; for my $foo(keys %{$userref->{$key}{'hash'}}) { push @{ $XmlRef->{$keyname}{'devices'}{'dev'.$cnt}{'param'} } , {id => $foo, content => $userref->{$key}{'hash'}{$foo}} ; $i+=1; }

Edit: struck out incorrect code.

"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: XMLout and keys/attributes
by atreyu (Sexton) on May 09, 2012 at 15:29 UTC
    Arggg! I just looked at the original code again, and I realized I screwed up the description of the XML. here is the correct $userref example:
    $userref->{0}{'hash'}{'Name'} = 'joe'; $userref->{0}{'hash'}{'Type'} = 'user'; $userref->{0}{'hash'}{'1Param'} = 'foo';
    and here is what I need the XML to look like:
    <key0> <devices> <dev0> <param id="Name">joe</param> <param id="Type">user</param> <param id="1Param">foo</param> </dev0> </devices> </key0>
    btw, your code suggestion was very close sauoq, care to try again?!
      btw, your code suggestion was very close sauoq, care to try again?!

      I already did. See my update? ;-)

      P.S. It should work with three params as well as two, so your "arrrggg" isn't needed. :-)

      "My two cents aren't worth a dime.";
        sauoq, your two cents are so money! you nailed it, thank you!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969643]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-01-17 03:33 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (196 votes). Check out past polls.