Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Help with attributes and XML::Simple

by Jenda (Abbot)
on Aug 01, 2012 at 16:11 UTC ( [id://984827]=note: print w/replies, xml ) Need Help??

in reply to Help with attributes and XML::Simple

See Simpler than XML::Simple for some reasons why you should not use XML::Simple and what to use instead.

As we do not know what do you need the data for, I can only guess in what format would you like them so just a tiny example. This code specifies that form each &lve;Vendor> you want the vendorUniqueKey as the key and the name as the value and then lets you execute some code to process this data once the </Vendors> tag is parsed. This style lets you process huge files without keeping everything in memory.

use strict; use XML::Rules; my $parser = XML::Rules->new( stripspaces => 7, rules => { Vendor => sub {return $_[1]->{vendorUniqueKey} => $_[1]->{name +}}, Vendors => sub { my ($tag, $vendors) = @_; print "We have " . scalar(keys %$vendors) . " vendors\n"; foreach (keys %$vendors) { print " $_ => $vendors->{$_}\n"; } return; }, ':default:' => '' } ); $parser->parse(\*DATA); __DATA__ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Import format="3.0" fileId="54630000-3141-1404-4310-7F0000014030" fil +eCreationDateTime="2+012-07-23T06:04:31.415" catalogSource="TLCMz"> <Catalog> <Vendors> <Vendor name="Allen Systems" vendorUniqueKey="ALLENGRP"/> <Vendor name="Aonix North America" vendorUniqueKey="AONIX"/> <Vendor name="Beta Systems Software" vendorUniqueKey="BETASY +S"/> <Vendor name="BMC Software" vendorUniqueKey="BMC"/> </Vendors> </Catalog> </Import>

Enoch was right!
Enjoy the last years of Rome.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-05-22 02:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found