likwid Posted January 26, 2007 Share Posted January 26, 2007 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 More sharing options...
hvle Posted January 26, 2007 Share Posted January 26, 2007 what is the PHP code you used to parse this? Link to comment https://forums.phpfreaks.com/topic/35771-simplexml-help/#findComment-169553 Share on other sites More sharing options...
likwid Posted January 26, 2007 Author Share Posted January 26, 2007 <?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 More sharing options...
likwid Posted January 26, 2007 Author Share Posted January 26, 2007 There is a br tag at the end of each line that got cut off when i pasted the code . "<br>"); Link to comment https://forums.phpfreaks.com/topic/35771-simplexml-help/#findComment-169816 Share on other sites More sharing options...
HBC Posted January 27, 2007 Share Posted January 27, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.