Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

parse xml
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


Report this thread to moderator Post Follow-up to this message
Old Post
E.Horn
10-25-04 08:56 PM


Re: parse xml
On 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


Report this thread to moderator Post Follow-up to this message
Old Post
Philipp Traeder
10-25-04 08:56 PM


Re: parse xml
From: "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


Report this thread to moderator Post Follow-up to this message
Old Post
Jenda Krynicky
10-25-04 08:56 PM


Re: parse xml
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Philipp Traeder
10-25-04 08:56 PM


Re: parse xml
I 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>
>


Report this thread to moderator Post Follow-up to this message
Old Post
Franklin
10-28-04 08:55 AM


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: 

> 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


Report this thread to moderator Post Follow-up to this message
Old Post
Philipp Traeder
10-28-04 01:55 PM


Re: parse xml
I 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>
>


Report this thread to moderator Post Follow-up to this message
Old Post
Franklin
10-28-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:52 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.