Solved

extracting data from an xml url with php

Posted on 2014-07-22
2
331 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
Comment Utility
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
Comment Utility
Well, that was much simpler than what I have been trying all afternoon.
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now