Code Comments
Programming Forum and web based access to our favorite programming groups.Hey! How can i pars this xmlfile? i just want to have the <MenueName>geo</MenueName> and the count out of this... <ResultItem> <DbName>geo</DbName> <MenuName>GEO Profiles</MenuName> <Count>69408</Count> <Status>Ok</Status> </ResultItem> <ResultItem> <DbName>gds</DbName> <MenuName>GEO DataSets</MenuName> <Count>8</Count> <Status>Ok</Status> </ResultItem> regards eve
Post Follow-up to this messageOn Monday 25 October 2004 16:27, E.Horn wrote:
> Hey!
> How can i pars this xmlfile?
> i just want to have the <MenueName>geo</MenueName> and the count out of
> this...
>
[..]
Hi,
I can highly recommend XML::Simple - just use it like this:
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use Data::Dumper;
my $ref = XMLin('xmlin.xml');
# now you've got the whole XML file in $ref:
print Dumper($ref);
print "\n";
print $ref->{'ResultItem'}->[0]{'MenuName'};
print "\t";
print $ref->{'ResultItem'}->[0]{'Count'} . "\n";
__END__
Now you can walk over the hash/array structure and everything's fine :-)
HTH,
Philipp
Post Follow-up to this messageFrom: "Traeder, Philipp" <Traeder@immobilienscout24.de>
> print $ref->{'ResultItem'}->[0]{'MenuName'};
I think it's better to either skip all the -> between subscriptions
or include them all:
print $ref->{'ResultItem'}[0]{'MenuName'};
or
print $ref->{'ResultItem'}->[0]->{'MenuName'};
It doesn't really matter of course.
Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
Post Follow-up to this messageOn Monday 25 October 2004 16:49, Jenda Krynicky wrote:
> From: "Traeder, Philipp" <Traeder@immobilienscout24.de>
>
>
> I think it's better to either skip all the -> between subscriptions
> or include them all:
>
> print $ref->{'ResultItem'}[0]{'MenuName'};
> or
> print $ref->{'ResultItem'}->[0]->{'MenuName'};
>
You're right - I should have taken another look at this before posting.
My main focus was on pointing out XML::Simple combined with Data::Dumper -
though this is *not* an excuse ;-).
Philipp
Post Follow-up to this messageI tried this one , but it seems not working:( Not an ARRAY reference at test.pl line 8 ----- Original Message ----- From: "Philipp Traeder" <philipp@hitchhackers.net> To: <beginners@perl.org> Sent: Monday, October 25, 2004 4:36 PM Subject: Re: parse xml > On Monday 25 October 2004 16:49, Jenda Krynicky wrote: > > You're right - I should have taken another look at this before posting. > My main focus was on pointing out XML::Simple combined with Data::Dumper - > though this is *not* an excuse ;-). > > Philipp > > -- > To unsubscribe, e-mail: beginners-unsubscribe@perl.org > For additional commands, e-mail: beginners-help@perl.org > <http://learn.perl.org/> <http://learn.perl.org/first-response> >
Post Follow-up to this messageHi Franklin, please bottom post (write your answer below the quoted text) - it's much easier to follow a thread this way. On Thursday 28 October 2004 02:11, Franklin wrote: > I tried this one , but it seems not working:( > Not an ARRAY reference at test.pl line 8 Taking a look at the other thread you opened on this list, my first guess is that your input files differ (your new file seems to have "ResultItemOne" as top level element while your original post's top level element was called "ResultItem"). I'd suggest to read the XML file via XML::Simple and to dump it via Data::Dumper - then you can see what the data structure looks like. After that you just need to play around a bit with array and hash references. If you run into problems with this, post the output of Data::Dumper to the list and somebody will be able to help. HTH, Philipp
Post Follow-up to this messageI have gotten it done. Thanks ----- Original Message ----- From: "Philipp Traeder" <philipp@hitchhackers.net> To: <beginners@perl.org> Sent: Thursday, October 28, 2004 5:40 AM Subject: Re: parse xml > Hi Franklin, > > please bottom post (write your answer below the quoted text) - it's much > easier to follow a thread this way. > > On Thursday 28 October 2004 02:11, Franklin wrote: > > > Taking a look at the other thread you opened on this list, my first guess > is > that your input files differ (your new file seems to have "ResultItemOne" > as > top level element while your original post's top level element was called > "ResultItem"). > > I'd suggest to read the XML file via XML::Simple and to dump it via > Data::Dumper - then you can see what the data structure looks like. After > that you just need to play around a bit with array and hash references. If > you run into problems with this, post the output of Data::Dumper to the > list > and somebody will be able to help. > > HTH, > > Philipp > > > -- > To unsubscribe, e-mail: beginners-unsubscribe@perl.org > For additional commands, e-mail: beginners-help@perl.org > <http://learn.perl.org/> <http://learn.perl.org/first-response> >
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.