For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2004 > how to parse this xml file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to parse this xml file
Franklin

2004-10-28, 3:55 am

Hey!
How can i parse this xmlfile?
As you can see, there are two <DbName>...</DbName> in both
<ResultItemOne> and <ResultItemTwo>. The first two <DbName> values and
last two <DbName> values must be treated different and be given two
different array. You guys have mentioned to use the method such as
print $ref->{'ResultItem'}[0]{'DbName'}. How can I use it in this kind
of scenario?

<ResultItemOne>
<DbName>geo</DbName>
<DbName>ceo</DbName>
<MenuName>GEO Profiles</MenuName>
<Count>69408</Count>
<Status>Ok</Status>
</ResultItemOne>

<ResultItemTwo>
<DbName>gds</DbName>
<DbName>cds</DbName>
<MenuName>GEO DataSets</MenuName>
<Count>8</Count>
<Status>Ok</Status>
</ResultItemTwo>

Thank you very much!
Chris Devers

2004-10-28, 3:55 am

On Wed, 27 Oct 2004, Franklin wrote:

> How can i parse this xmlfile?


That depends on what XML parsing module you're using.

You never seem to state that.

For that matter, you never show what you've tried so far.

Please tell us what you have tried so far.



--
Chris Devers
Franklin

2004-10-28, 3:55 am

I have tried in this manner:

use XML::XPath;

my $xp=XML::XPath->new(filename=>"xmlin.xml");
my $nodeset1=$xp->find('//DbName');
my @zipcodes1;
if(my @nodelist1=$nodeset1->get_nodelist){
@zipcodes1=map($_->string_value,@nodelist1);
$number=@zipcodes1;
local $"="\n";
}

But by using this method I can't distinguish between the first two
DbName value and the last two.
How to solve it?
Thank you very much!



On Wed, 27 Oct 2004 21:45:30 -0400 (EDT), Chris Devers
<cdevers@pobox.com> wrote:
> On Wed, 27 Oct 2004, Franklin wrote:
>
>
> That depends on what XML parsing module you're using.
>
> You never seem to state that.
>
> For that matter, you never show what you've tried so far.
>
> Please tell us what you have tried so far.
>
> --
> Chris Devers
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com