Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:49:51+00:00 2026-06-11T19:49:51+00:00

I’m just learning PERL. I’ve read some docs on parsing XML and reused some

  • 0

I’m just learning PERL. I’ve read some docs on parsing XML and reused some of my colleague’s code. But I can’t seem to get it to simply print out a list of the 3 football player names in this data. Please help. Here is the PERL code:

    #! /usr/bin/perl -w
use strict;
use DBI;
use XML::Simple;
use LWP::UserAgent;
use HTTP::Request;
use Time::gmtime;
use Time::Local;
use Data::Dumper;

sub statsInit(){
  my $xml_api_url = "http://myprovider.com/nfldata.xml";
  my $xml = getXML($xml_api_url);
  my $xmlData = xml2Simple($xml);
  print "Hello World";
  foreach my $player (@{$xmlData->{player}}){
    my $playername = $player->{name};
    print "pn = $playername | ";
  }
}


sub getXML($){
    my ($xmlURL) = @_;
    my $dataresponse = '';
    my $agent = LWP::UserAgent->new(env_proxy => 1, keep_alive => 1, timeout => 100);
    my $header = HTTP::Request->new(GET => $xmlURL);
    my $request = HTTP::Request->new('GET', $xmlURL, $header);
    my $response = $agent->request($request);
    if($response->is_success){
        $dataresponse = $response->content(); #Loaded data from FINAL_XML
    }
    return $dataresponse;
}

sub xml2Simple(){
    my ($xml) = @_;
    my $xmlObj = XML::Simple->new(KeyAttr => {});
    my $xmlData = '';
    my $parsedData = '';
    if($xml){
        $xmlData = $xmlObj->XMLin($xml);
    }
    return $xmlData;
}

statsInit();
-------- NOW BELOW IS THE RETRIEVED XML DATA --------
    <season xmlns="http://myprovider.com/schema/nfl/statistics-v1.0.xsd" season="2012" season_type="REG">
<team id="BUF" name="Bills" market="Buffalo">
    <players>
        <player id="100" name="Nick Barnett" games_played="1" games_started="1" jersey="50" position="OLB">
            <defense tackle="7" ast="2" />
        </player>
        <player id="101" name="Ryan Fitzpatrick" games_played="1" games_started="1" jersey="14" position="QB">
            <rushing att="2" yds="8" />
            <passing att="32" cmp="18" yds="195" td="3" int="3"/>
        </player>
        <player id="102" name="Fred Jackson" games_played="1" games_started="1" jersey="22" position="RB">
            <rushing att="6" yds="15" td="0"/>
        </player>
    </players>
</team>
</season>

So my code seems to retrieve the data ok, and I get no errors. “Hello World” gets printed. But it never goes into the players loop and doesn’t print any player names. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:49:52+00:00Added an answer on June 11, 2026 at 7:49 pm

    I figured it out. I guess I had to change this line.

    foreach my $player (@{$xmlData->{player}}){
    

    to this:

    foreach my $player (@{$xmlData->{team}{players}{player}}){  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm parsing an XML file, the creators of it stuck in a bunch social
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.