Jump to content

SimpleXML Help


likwid

Recommended Posts

I am trying to parse an xml file with this structure:

<?xml version="1.0" encoding="UTF-8"?>
<updates>
<country iso_code="US">
  <name lang="en">United States</name>
  <state abbreviation="AL">
<name lang="en">Alabama</name>
<city>
  <name lang="en">Anniston</name>
  <location id="70276" venue_id="61058" category="Retail Business" name="The UPS Store 3330" location_description="" address="1414 Golden Springs Rd" zipcode="36207" areacode="256" phone_number="835 8884" wispr_location_id="" wispr_location_name=""/>
</city>
<city>
  <name lang="en">Athens</name>
  <location id="174304" venue_id="150560" category="Hotel" name="CO - Sleep Inn - Athens AL" location_description="" address="1115 Audubon Lane" zipcode="35611" areacode="" phone_number="256-232-4700" wispr_location_id="" wispr_location_name=""/>
</city>
<city>
  <name lang="en">Bessemer</name>
  <location id="176734" venue_id="153499" category="Hotel" name="CO - Comfort Inn - Bessemer AL" location_description="" address="5051 Academy Lane" zipcode="35022" areacode="" phone_number="205-428-3999" wispr_location_id="" wispr_location_name=""/>
</city>
</state>
</country>
</updates>

I get to the state name and can't get any further. Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/35771-simplexml-help/
Share on other sites

<?php
$updates = simplexml_load_file('phonebook.xml');

      foreach ($updates->country as $country) {
  printf("Country: %s\n", $country->name . "<br>");
      printf("State: %s\n", $country->state[0]->name . "<br>");
  printf("City: %s\n", $country->state[1]->city->name . "<br>");

  }
?>

I can parse up to state...?
Link to comment
https://forums.phpfreaks.com/topic/35771-simplexml-help/#findComment-169801
Share on other sites

Try this:
[code]
<?php
$updates = simplexml_load_file('phonebook.xml');

      foreach ($updates->country as $country) {
    printf("Country: %s\n", $country['name'] . "
");
      printf("State: %s\n", $country->state['name'] . "
");
    printf("City: %s\n", $country->state[1]->city['name'] . "
");
 
  }
?>
[/code]
You get what I mean.. That works for me when using simplexml..
Link to comment
https://forums.phpfreaks.com/topic/35771-simplexml-help/#findComment-170484
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.