Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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>

Jenda
Enoch was right!
Enjoy the last years of Rome.


In reply to Re: Help with attributes and XML::Simple by Jenda
in thread Help with attributes and XML::Simple by Smaug

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-06-18 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.