Some time ago, Will Partain wrote: > Folks, I wasn't pleased with my initial skirmish with XML::Parser, > trying to do the task below, so I thought I would ask how people here > would go about it. (I had no difficulty with clunky solutions, but > nothing even slightly elegant sprang from my wee brain.) > > The input is from an xml-as-interchange-format world; imagine I have > records something like... > > > netscape.com > > Netscape > > active > > communicator-4.07, communicator-4.5, navigator-4.07 > > > > I want some code to go slurp!, such that I end up with a VendorInfo > object so that, in the rest of my code, I can just > do... $vendor->name(), $vendor->packages(), ... > > The slurping code (what I'm missing) needs to do the obvious things: > well-formedness, check that isn't given twice, ... > > Actually, it should all be abstracted up a level, given that I'll > have many more types of "infos", besides just vendors. So I'd > really like a slurper that, given a list of mandatory and optional > tags, would give me back what I wanted. Well, you get the > picture... Ideas? use XML::DT; %handler = ( -default => sub{$c}, # $c has the contents... packages => sub{ [ split(",",$c)] }, -type => { vendorinfo => 'MAP' } ); $a = dt("vendorfilename",%handler); which makes $a a ref to { 'name' => ' Netscape ', 'status' => ' active ', 'id' => ' netscape.com', 'packages' => [ ' communicator-4.07', ' communicator-4.5', ' navigator-4.07 ' ] }; Other possible types: SEQ, STR, MULTIMAP More information in pod documentation if the module. http://www.di.uminho.pt/~jj/perl/XML/DT.html Feedback about this would be precious Um abraco J.Joao