Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: XML::Simple help

by saintmike (Vicar)
on Mar 08, 2005 at 00:47 UTC ( [id://437371]=note: print w/replies, xml ) Need Help??


in reply to XML::Simple help

Not sure if XML::Simple can do it, but a little post processing will do:
my $ref = XMLin($data, KeyAttr => { charge => "code"}); my %hash = map { ($_, $ref->{charge}->{$_}->{name}) } keys %{$ref->{charge}}; $ref = \%hash;

Replies are listed 'Best First'.
Re^2: XML::Simple help
by holli (Abbot) on Mar 08, 2005 at 06:01 UTC
    That's something I'd like to have in a class.
    package ChargeTypeXML; sub new { my $class = shift; my %args = shift; my $ref = XMLin($args->{file}, KeyAttr => { charge => "code"}); my %hash = map { ($_, $ref->{charge}->{$_}->{name}) } keys %{$ref->{charge}}; $ref = \%hash; bless $ref, $class; return $ref; } sub toXML { print qq{<?xml version="1.0" encoding="UTF-8" ?>\n}; print qq{<charge-type-control>\n}; for keys ( %{$self} ) { print qq{<charge code="$_" name="}, $self->{$_}, qq{frtamt"/>\n}; } print qq{</charge-type-control>}; } 1; #in the script: use ChargeTypeXML; my $xml = ChargeTypeXML->new (file=>"xmlfile");

    Of course this only works, when all "codes" in the xml are unique.

    Note: untested


    holli, /regexed monk/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://437371]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found