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 8605053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:43:44+00:00 2026-06-12T02:43:44+00:00

I am trying to read this XML document with php. https://raw.github.com/yosoyadri/GeoNames-XML-Builder/master/continents-countries-statesprovinces.xml That is what

  • 0

I am trying to read this XML document with php.

https://raw.github.com/yosoyadri/GeoNames-XML-Builder/master/continents-countries-statesprovinces.xml

That is what I figured out so far.

$xml = new SimpleXMLElement(file_get_contents(TEMPLATEPATH.'/lib/regions.xml'));
echo $xml->Children[0]->SimpleGeoName[0]->Id;

I do not know how I can loop through all countries and store them using php. I am really new to xml parsing and I am not even sure if I am able to loop thru all results like this. because $xml->Children->.. returns empty.

Any help greatly appreciate it.

  • 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-12T02:43:45+00:00Added an answer on June 12, 2026 at 2:43 am

    This is how you loop through the xml

    echo "<pre>";
    $xml = new SimpleXMLElement(file_get_contents("regions.xml"));
    foreach ( $xml->Children as $region ) { // iterate through all the regions
        foreach ( $region as $continent ) {
            echo "Continet ID :", $continent->Id . PHP_EOL;
            echo "Continet Name :", $continent->Name . PHP_EOL;
    
            echo PHP_EOL;
    
            foreach ( $continent->Children as $countryList ) {
                foreach ( $countryList as $country ) {
                    // var_dump($country);
                    echo "\tCountry ID :", $country->Id . PHP_EOL;
                    echo "\tCountry Name  :", $country->Name . PHP_EOL;
    
                    echo PHP_EOL;
                }
            }
        }
    }
    

    Output

    Continet ID :6255146
    Continet Name :Africa
    
        Country ID :2589581
        Country Name  :Algeria
    
        Country ID :3351879
        Country Name  :Angola
    
        Country ID :2395170
        Country Name  :Benin
    
        Country ID :933860
        Country Name  :Botswana
    
        Country ID :2361809
        Country Name  :Burkina Faso
    
        Country ID :433561
        Country Name  :Burundi
    
        Country ID :2233387
        Country Name  :Cameroon
    
        Country ID :3374766
        Country Name  :Cape Verde
    
        Country ID :239880
        Country Name  :Central African Republic
    
        Country ID :2434508
        Country Name  :Chad
    
        Country ID :921929
        Country Name  :Comoros
    
        Country ID :203312
        Country Name  :Congo
    
        Country ID :223816
        Country Name  :Djibouti
    
        Country ID :357994
        Country Name  :Egypt
    
        Country ID :2309096
        Country Name  :Equatorial Guinea
    
        Country ID :338010
        Country Name  :Eritrea
    
        Country ID :337996
        Country Name  :Ethiopia
    
        Country ID :2400553
        Country Name  :Gabon
    
        Country ID :2413451
        Country Name  :Gambia
    
        Country ID :2300660
        Country Name  :Ghana
    
        Country ID :2420477
        Country Name  :Guinea
    
        Country ID :2372248
        Country Name  :Guinea-Bissau
    
        Country ID :2287781
        Country Name  :Ivory Coast
    
        Country ID :192950
        Country Name  :Kenya
    
        Country ID :932692
        Country Name  :Lesotho
    
        Country ID :2275384
        Country Name  :Liberia
    
        Country ID :2215636
        Country Name  :Libya
    
        Country ID :1062947
        Country Name  :Madagascar
    
        Country ID :927384
        Country Name  :Malawi
    
        Country ID :2453866
        Country Name  :Mali
    
        Country ID :2378080
        Country Name  :Mauritania
    
        Country ID :934292
        Country Name  :Mauritius
    
        Country ID :1024031
        Country Name  :Mayotte
    
        Country ID :2542007
        Country Name  :Morocco
    
        Country ID :1036973
        Country Name  :Mozambique
    
        Country ID :3355338
        Country Name  :Namibia
    
        Country ID :2440476
        Country Name  :Niger
    
        Country ID :2328926
        Country Name  :Nigeria
    
        Country ID :2260494
        Country Name  :Republic of the Congo
    
        Country ID :49518
        Country Name  :Rwanda
    
        Country ID :935317
        Country Name  :Réunion
    
        Country ID :3370751
        Country Name  :Saint Helena
    
        Country ID :2245662
        Country Name  :Senegal
    
        Country ID :241170
        Country Name  :Seychelles
    
        Country ID :2403846
        Country Name  :Sierra Leone
    
        Country ID :51537
        Country Name  :Somalia
    
        Country ID :953987
        Country Name  :South Africa
    
        Country ID :7909807
        Country Name  :South Sudan
    
        Country ID :366755
        Country Name  :Sudan
    
        Country ID :934841
        Country Name  :Swaziland
    
        Country ID :2410758
        Country Name  :São Tomé and Príncipe
    
        Country ID :149590
        Country Name  :Tanzania
    
        Country ID :2363686
        Country Name  :Togo
    
        Country ID :2464461
        Country Name  :Tunisia
    
        Country ID :226074
        Country Name  :Uganda
    
        Country ID :2461445
        Country Name  :Western Sahara
    
        Country ID :895949
        Country Name  :Zambia
    
        Country ID :878675
        Country Name  :Zimbabwe
    
    Continet ID :6255152
    Continet Name :Antarctica
    
        Country ID :6697173
        Country Name  :Antarctica
    
        Country ID :3371123
        Country Name  :Bouvet Island
    
        Country ID :1546748
        Country Name  :French Southern Territories
    
        Country ID :1547314
        Country Name  :Heard Island and McDonald Islands
    
        Country ID :3474415
        Country Name  :South Georgia and the South Sandwich Islands
    
    Continet ID :6255147
    Continet Name :Asia
    
        Country ID :1149361
        Country Name  :Afghanistan
    
        Country ID :174982
        Country Name  :Armenia
    
        Country ID :587116
        Country Name  :Azerbaijan
    
        Country ID :290291
        Country Name  :Bahrain
    
        Country ID :1210997
        Country Name  :Bangladesh
    
        Country ID :1252634
        Country Name  :Bhutan
    
        Country ID :1282588
        Country Name  :British Indian Ocean Territory
    
        Country ID :1820814
        Country Name  :Brunei
    
        Country ID :1831722
        Country Name  :Cambodia
    
        Country ID :1814991
        Country Name  :China
    
        Country ID :2078138
        Country Name  :Christmas Island
    
        Country ID :1547376
        Country Name  :Cocos [Keeling] Islands
    
        Country ID :614540
        Country Name  :Georgia
    
        Country ID :1819730
        Country Name  :Hong Kong
    
        Country ID :1269750
        Country Name  :India
    
        Country ID :1643084
        Country Name  :Indonesia
    
        Country ID :130758
        Country Name  :Iran
    
        Country ID :99237
        Country Name  :Iraq
    
        Country ID :294640
        Country Name  :Israel
    
        Country ID :1861060
        Country Name  :Japan
    
        Country ID :248816
        Country Name  :Jordan
    
        Country ID :1522867
        Country Name  :Kazakhstan
    
        Country ID :285570
        Country Name  :Kuwait
    
        Country ID :1527747
        Country Name  :Kyrgyzstan
    
        Country ID :1655842
        Country Name  :Laos
    
        Country ID :272103
        Country Name  :Lebanon
    
        Country ID :1821275
        Country Name  :Macao
    
        Country ID :1733045
        Country Name  :Malaysia
    
        Country ID :1282028
        Country Name  :Maldives
    
        Country ID :2029969
        Country Name  :Mongolia
    
        Country ID :1327865
        Country Name  :Myanmar [Burma]
    
        Country ID :1282988
        Country Name  :Nepal
    
        Country ID :1873107
        Country Name  :North Korea
    
        Country ID :286963
        Country Name  :Oman
    
        Country ID :1168579
        Country Name  :Pakistan
    
        Country ID :6254930
        Country Name  :Palestine
    
        Country ID :1694008
        Country Name  :Philippines
    
        Country ID :289688
        Country Name  :Qatar
    
        Country ID :102358
        Country Name  :Saudi Arabia
    
        Country ID :1880251
        Country Name  :Singapore
    
        Country ID :1835841
        Country Name  :South Korea
    
        Country ID :1227603
        Country Name  :Sri Lanka
    
        Country ID :163843
        Country Name  :Syria
    
        Country ID :1668284
        Country Name  :Taiwan
    
        Country ID :1220409
        Country Name  :Tajikistan
    
        Country ID :1605651
        Country Name  :Thailand
    
        Country ID :298795
        Country Name  :Turkey
    
        Country ID :1218197
        Country Name  :Turkmenistan
    
        Country ID :290557
        Country Name  :United Arab Emirates
    
        Country ID :1512440
        Country Name  :Uzbekistan
    
        Country ID :1562822
        Country Name  :Vietnam
    
        Country ID :69543
        Country Name  :Yemen
    
    Continet ID :6255148
    Continet Name :Europe
    
        Country ID :783754
        Country Name  :Albania
    
        Country ID :3041565
        Country Name  :Andorra
    
        Country ID :2782113
        Country Name  :Austria
    
        Country ID :630336
        Country Name  :Belarus
    
        Country ID :2802361
        Country Name  :Belgium
    
        Country ID :3277605
        Country Name  :Bosnia and Herzegovina
    
        Country ID :732800
        Country Name  :Bulgaria
    
        Country ID :3202326
        Country Name  :Croatia
    
        Country ID :146669
        Country Name  :Cyprus
    
        Country ID :3077311
        Country Name  :Czech Republic
    
        Country ID :2623032
        Country Name  :Denmark
    
        Country ID :453733
        Country Name  :Estonia
    
        Country ID :2622320
        Country Name  :Faroe Islands
    
        Country ID :660013
        Country Name  :Finland
    
        Country ID :3017382
        Country Name  :France
    
        Country ID :2921044
        Country Name  :Germany
    
        Country ID :2411586
        Country Name  :Gibraltar
    
        Country ID :390903
        Country Name  :Greece
    
        Country ID :719819
        Country Name  :Hungary
    
        Country ID :2629691
        Country Name  :Iceland
    
        Country ID :2963597
        Country Name  :Ireland
    
        Country ID :3175395
        Country Name  :Italy
    
        Country ID :831053
        Country Name  :Kosovo
    
        Country ID :458258
        Country Name  :Latvia
    
        Country ID :3042058
        Country Name  :Liechtenstein
    
        Country ID :597427
        Country Name  :Lithuania
    
        Country ID :2960313
        Country Name  :Luxembourg
    
        Country ID :718075
        Country Name  :Macedonia
    
        Country ID :2562770
        Country Name  :Malta
    
        Country ID :617790
        Country Name  :Moldova
    
        Country ID :2993457
        Country Name  :Monaco
    
        Country ID :3194884
        Country Name  :Montenegro
    
        Country ID :2750405
        Country Name  :Netherlands
    
        Country ID :3144096
        Country Name  :Norway
    
        Country ID :798544
        Country Name  :Poland
    
        Country ID :2264397
        Country Name  :Portugal
    
        Country ID :798549
        Country Name  :Romania
    
        Country ID :2017370
        Country Name  :Russia
    
        Country ID :3168068
        Country Name  :San Marino
    
        Country ID :6290252
        Country Name  :Serbia
    
        Country ID :3057568
        Country Name  :Slovakia
    
        Country ID :3190538
        Country Name  :Slovenia
    
        Country ID :2510769
        Country Name  :Spain
    
        Country ID :607072
        Country Name  :Svalbard and Jan Mayen
    
        Country ID :2661886
        Country Name  :Sweden
    
        Country ID :2658434
        Country Name  :Switzerland
    
        Country ID :690791
        Country Name  :Ukraine
    
        Country ID :2635167
        Country Name  :United Kingdom
    
        Country ID :3164670
        Country Name  :Vatican City
    
        Country ID :661882
        Country Name  :Ã…land
    
    Continet ID :6255149
    Continet Name :North America
    
        Country ID :3573511
        Country Name  :Anguilla
    
        Country ID :3576396
        Country Name  :Antigua and Barbuda
    
        Country ID :3577279
        Country Name  :Aruba
    
        Country ID :3572887
        Country Name  :Bahamas
    
        Country ID :3374084
        Country Name  :Barbados
    
        Country ID :3582678
        Country Name  :Belize
    
        Country ID :3573345
        Country Name  :Bermuda
    
        Country ID :7626844
        Country Name  :Bonaire
    
        Country ID :3577718
        Country Name  :British Virgin Islands
    
        Country ID :6251999
        Country Name  :Canada
    
        Country ID :3580718
        Country Name  :Cayman Islands
    
        Country ID :3624060
        Country Name  :Costa Rica
    
        Country ID :3562981
        Country Name  :Cuba
    
        Country ID :7626836
        Country Name  :Curacao
    
        Country ID :3575830
        Country Name  :Dominica
    
        Country ID :3508796
        Country Name  :Dominican Republic
    
        Country ID :3585968
        Country Name  :El Salvador
    
        Country ID :3425505
        Country Name  :Greenland
    
        Country ID :3580239
        Country Name  :Grenada
    
        Country ID :3579143
        Country Name  :Guadeloupe
    
        Country ID :3595528
        Country Name  :Guatemala
    
        Country ID :3723988
        Country Name  :Haiti
    
        Country ID :3608932
        Country Name  :Honduras
    
        Country ID :3489940
        Country Name  :Jamaica
    
        Country ID :3570311
        Country Name  :Martinique
    
        Country ID :3996063
        Country Name  :Mexico
    
        Country ID :3578097
        Country Name  :Montserrat
    
        Country ID :3617476
        Country Name  :Nicaragua
    
        Country ID :3703430
        Country Name  :Panama
    
        Country ID :4566966
        Country Name  :Puerto Rico
    
        Country ID :3578476
        Country Name  :Saint Barthélemy
    
        Country ID :3575174
        Country Name  :Saint Kitts and Nevis
    
        Country ID :3576468
        Country Name  :Saint Lucia
    
        Country ID :3578421
        Country Name  :Saint Martin
    
        Country ID :3424932
        Country Name  :Saint Pierre and Miquelon
    
        Country ID :3577815
        Country Name  :Saint Vincent and the Grenadines
    
        Country ID :7609695
        Country Name  :Sint Maarten
    
        Country ID :3573591
        Country Name  :Trinidad and Tobago
    
        Country ID :3576916
        Country Name  :Turks and Caicos Islands
    
        Country ID :4796775
        Country Name  :U.S. Virgin Islands
    
        Country ID :6252001
        Country Name  :United States
    
    Continet ID :6255151
    Continet Name :Oceania
    
        Country ID :5880801
        Country Name  :American Samoa
    
        Country ID :2077456
        Country Name  :Australia
    
        Country ID :1899402
        Country Name  :Cook Islands
    
        Country ID :2170371
        Country Name  :Coral Sea Islands Territory
    
        Country ID :1966436
        Country Name  :East Timor
    
        Country ID :2205218
        Country Name  :Fiji
    
        Country ID :4030656
        Country Name  :French Polynesia
    
        Country ID :4043988
        Country Name  :Guam
    
        Country ID :4030945
        Country Name  :Kiribati
    
        Country ID :2080185
        Country Name  :Marshall Islands
    
        Country ID :2081918
        Country Name  :Micronesia
    
        Country ID :2110425
        Country Name  :Nauru
    
        Country ID :2139685
        Country Name  :New Caledonia
    
        Country ID :2186224
        Country Name  :New Zealand
    
        Country ID :4036232
        Country Name  :Niue
    
        Country ID :2155115
        Country Name  :Norfolk Island
    
        Country ID :4041468
        Country Name  :Northern Mariana Islands
    
        Country ID :1559582
        Country Name  :Palau
    
        Country ID :2088628
        Country Name  :Papua New Guinea
    
        Country ID :4030699
        Country Name  :Pitcairn Islands
    
        Country ID :4034894
        Country Name  :Samoa
    
        Country ID :2103350
        Country Name  :Solomon Islands
    
        Country ID :2077507
        Country Name  :Territory of Ashmore and Cartier Islands
    
        Country ID :4031074
        Country Name  :Tokelau
    
        Country ID :4032283
        Country Name  :Tonga
    
        Country ID :2110297
        Country Name  :Tuvalu
    
        Country ID :5854968
        Country Name  :U.S. Minor Outlying Islands
    
        Country ID :2134431
        Country Name  :Vanuatu
    
        Country ID :4034749
        Country Name  :Wallis and Futuna
    
    Continet ID :6255150
    Continet Name :South America
    
        Country ID :3865483
        Country Name  :Argentina
    
        Country ID :3923057
        Country Name  :Bolivia
    
        Country ID :3469034
        Country Name  :Brazil
    
        Country ID :3895114
        Country Name  :Chile
    
        Country ID :3686110
        Country Name  :Colombia
    
        Country ID :3658394
        Country Name  :Ecuador
    
        Country ID :3474414
        Country Name  :Falkland Islands
    
        Country ID :3381670
        Country Name  :French Guiana
    
        Country ID :3378535
        Country Name  :Guyana
    
        Country ID :3437598
        Country Name  :Paraguay
    
        Country ID :3932488
        Country Name  :Peru
    
        Country ID :3382998
        Country Name  :Suriname
    
        Country ID :3439705
        Country Name  :Uruguay
    
        Country ID :3625428
        Country Name  :Venezuela
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are trying to read information from a separate XML document. This is the
I am trying to read a XML document with C#, I am doing it
I'm trying to read an xml document but the XmlReader.ReadToNextSibling does not work as
I have a simple XML document I'm trying to read in with Python DOM
Hello I am trying to read my xml document using xpath. I have been
I'm trying to read/copy a certain part of a xml document in JAVA and
looks like I need help again! :-/ Im trying to read this XML file
I am trying to read the XML Documentation file (C#) using this ocde -
I am trying to read this .csv file and here is an example of
I am trying to read this file I created as sample made up from

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.