We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30585
    • 833 Posts
    Hey guys,

    I really don’t anything about XML except that it’s awesome and indispensable.

    I managed to get an XML output code for Google’s weather API and I’d like to know how to output it in HTML. I know that there must be some PHP involved and I was wondering if someone can take a look and help the brother out. I’m sure the community will benefit from this.

    Here’s the code:

    <xml_api_reply version="1">
      <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
        <forecast_information>
    	  <city data="Toronto, ON"/>
    	  <postal_code data="Toronto"/>
    	  <latitude_e6 data=""/>
    	  <longitude_e6 data=""/>
    	  <forecast_date data="2011-03-11"/>
    	  <current_date_time data="2011-03-11 15:07:00 +0000"/>
    	  <unit_system data="US"/>
    	</forecast_information>
    	<current_conditions>
    	  <condition data="Rain and Snow"/>
    	  <temp_f data="36"/>
    	  <temp_c data="2"/>
    	  <humidity data="Humidity: 100%"/>
    	  <icon data="/ig/images/weather/rain_snow.gif"/>
    	  <wind_condition data="Wind: S at 6 mph"/>
    	</current_conditions>
    	<forecast_conditions>
    	  <day_of_week data="Fri"/>
    	  <low data="31"/>
    	  <high data="37"/>
    	  <icon data="/ig/images/weather/rain_snow.gif"/>
    	  <condition data="Rain and Snow"/>
    	</forecast_conditions>
    	<forecast_conditions>
    	  <day_of_week data="Sat"/>
    	  <low data="28"/><high data="38"/>
    	  <icon data="/ig/images/weather/rain_snow.gif"/>
    	  <condition data="Rain and Snow"/>
    	</forecast_conditions>
    	<forecast_conditions>
    	  <day_of_week data="Sun"/>
    	  <low data="18"/>
    	  <high data="32"/>
    	  <icon data="/ig/images/weather/snow.gif"/>
    	  <condition data="Snow Showers"/>
    	</forecast_conditions>
    	<forecast_conditions>
    	  <day_of_week data="Mon"/>
    	  <low data="23"/><high data="32"/>
    	  <icon data="/ig/images/weather/partly_cloudy.gif"/>
    	  <condition data="Partly Cloudy"/>
    	</forecast_conditions>
      </weather>
    </xml_api_reply>
      A MODx Fanatic
      • 6228
      • 249 Posts
      You can parse the XML into a simple PHP array or object using the PHP SimpleXML extension, or you can use something like this: www.bin-co.com/php/scripts/xml2array/

      Of course once you have your array, just pull the fields and wrap them in HTML tags however works best for you.
        lo9on.com

        MODx Evolution/Revolution | Remote Desktop Training | Development
        • 30585
        • 833 Posts
        This is great, thanks!

        I’ll work on this and post the final results for all to see.

        Thanks again
          A MODx Fanatic