Solved

extracting data from an xml url with php

Posted on 2014-07-22
2
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
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 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…

617 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