Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: XML::Simple help

by holli (Monsignor)
on Mar 08, 2005 at 06:01 UTC ( #437427=note: print w/replies, xml ) Need Help??


in reply to Re: XML::Simple help
in thread XML::Simple help

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
Node Status?
node history
Node Type: note [id://437427]
help
Chatterbox?
[Corion]: Whoops - more spam - I guess I'll have to collate a list and have them banned later today
[Corion]: Maybe I should bring my Github credentials to $work some day, just to open issues for blogs.perl.org ;)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-02-24 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (354 votes). Check out past polls.