Solved

extracting data from an xml url with php

Posted on 2014-07-22
2
336 Views
Last Modified: 2014-07-22
I am trying to extract three variables from a site that returns an xml file. It contains, among other things, the Latitude, Longitude, CensusTract and CensusBlock.
I am attaching a file that represents what I am trying to do. I just can't figure out the syntax to address the xml data.
xmlpuzle.php
0
Comment
Question by:Cal_George
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40213237
Simple example - you just need to drill down the nodes for any value you want
<?php
$url = 'https://geoservices.tamu.edu/Services/Geocode/WebService/GeocoderWebServiceHttpNonParsed_V04_01.aspx?streetAddress=500%20McMahon%20Road&city=Hollister&state=ca&zip=95023&apikey=demo&format=XML&census=true&censusYear=2010&notStore=false&version=4.01';

$xml=simplexml_load_file($url);
echo "Latitude: ".$xml->OutputGeocodes[0]->OutputGeocode->Latitude."<br>";
echo "Longitude: ".$xml->OutputGeocodes[0]->OutputGeocode->Longitude."<br>";
echo "CensusTract: ".$xml->OutputGeocodes[0]->OutputGeocode->CensusValues->CensusValue->CensusTract."<br>";

Open in new window

0
 
LVL 2

Author Closing Comment

by:Cal_George
ID: 40213339
Well, that was much simpler than what I have been trying all afternoon.
Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question