in reply to Re: Newbie XML Simple reference
in thread Newbie XML Simple reference

I checked the link(s) but now I am more worried I will not be able to make my script. Perl is, imo, quite complicated if you never saw referencing like that. How can I get a list of attributes within an element ?
Like for this xml
<node class="1" name="name1" type="type1" ... >
What outputs this:
You have 3 attributes:
class
name
type
?
Without using the node in code... So in a loop, and not like {node} , that is not how to program
Keep in mind that I use the XML::Simple.
Thanks so much for the help !!!

Replies are listed 'Best First'.
Re^3: Newbie XML Simple reference
by Anonymous Monk on Nov 05, 2008 at 11:59 UTC
    Do your part, set it up.
      Sorry Guys, I am a Perl noob. My problem is that I cannot spend time studying this language. My boss wont let me
      I need an output like this:

      You have 2 tags: node and node
      In node you have attribute type and name with values k and n
      This is the output i am looking for, for this xml
      XML
      ----
      <XML> <element> <node type="k" name="n"/> <node type="i" name="q"/> </element> </XML>
      Dummy Code
      #!/usr/bin/perl -- use strict; use warnings; use XML::Simple; my $xs1 = XML::Simple->new(); my $doc = $xs1->XMLin($file, keyattr=>['????'], ForceContent=>1, Force +Array=>1); use Data::Dumper; local $Data::Dumper::Indent=1; print Dumper($doc); for my $sub ( sort keys %{ $doc->{????} } ){ for my $elem ( sort keys %{ $doc->{????}->{$sub} } ){ } }