Re: XML::Simple array size




<robic0> wrote in message news:g5uno11r6901vv00tnpln9r35j3q4v3jfc@xxxxxxxxxx
> On Sat, 14 Feb 2004 17:58:08 -0500, Mark J Fenbers
> <Mark.Fenbers@xxxxxxxx> wrote:
>
>>In my sample XML file...
>>
>><main>
>> <level1>
>> <level2>whatever</level2>
>> <level2>whatever</level2>
>> <level2>whatever</level2>
>> <level2>whatever</level2>
>> <level2>whatever</level2>
>> ...
>> </level1>
>></main>
>>
>>I have an variable number of level2 tags. Using XML::Simple, I can access
>>the
>>value of the 4th one by something like this:
>>
>> my $main = XMLin("myfile.xml");
>> print $main->{level1}->{level2}->[3]->{content};
>>
>>But I really want to know how many level2 records there are. I tried
>>variations
>>
> Hey isn't the "$main" name take already?
> New rule, you have to give more details than "I want to count all
> animals on Noah's ark". Noah didn't coun't them for a reason....
> Unless you positively know ahead of time the structure of the xml
> in question, you can't rely on xml::simple's output structure.
> I guess thats the other question.....

Answering the OP's question. If there are a variable number <level2>
my $element_count = @{ $main->{level1}->{level2} };
should do it (untested).
If there is only one level2 this will give an error unless you force
XML::Simple to make it an array.


.



Relevant Pages

  • Re: XML::Simple array size
    ... >>>In my sample XML file... ... >>>But I really want to know how many level2 records there are. ...
    (comp.lang.perl.misc)
  • XML::Simple array size
    ... In my sample XML file... ... I have an variable number of level2 tags. ... But I really want to know how many level2 records there are. ... proper Perl hash array syntax to determine the number of elements of the level2 ...
    (comp.lang.perl.modules)
  • XML::Simple array size
    ... In my sample XML file... ... I have an variable number of level2 tags. ... But I really want to know how many level2 records there are. ... proper Perl hash array syntax to determine the number of elements of the level2 ...
    (comp.lang.perl.misc)
  • Re: XML::Simple array size
    ... >In my sample XML file... ... >I have an variable number of level2 tags. ... Noah didn't coun't them for a reason.... ... you can't rely on xml::simple's output structure. ...
    (comp.lang.perl.misc)