We help IT Professionals succeed at work.

How to markup XML passed in a URL - Petfinder API

ambientsbs asked
Last Modified: 2012-05-11

I am working with the Petfinder API to create a tool that will allow people to search for pets. The way that this API works is that you generate a URL with your specific API key and some variables. The string looks like such:


With a proper API key, this URL will return an XML page that has a ton of information about animals that meet the criteria. In the case above, it would show every animal near the location of Reno, NV.

What I'm trying to figure out is how I can pass the URL that returns all of the XML code to an HTML or PHP page that I can then markup. Basically, I want to use the information in the XML to populate a page with information and pictures. Attached is an example of what the XML code looks like. Any help is much appreciated or if someone can point me in the direction of a website that explains how to do this I would be grateful!

- <pets>
- <pet>
  <shelterPetId /> 
- <breeds>
  <breed>Australian Shepherd</breed> 
  <breed>Border Collie</breed> 
- <options>
- <description>
- <![CDATA[ 
<div><p>Megan is a real character. She is an aussie border collie mix. She has been deaf her whole life but you&#39;d never know it. megan loves everyone and would make a great companion.<p><em><strong> If you are interested in this dog, please visit <a href="http://aussiebcrescue.com/adoptapp.htm" onclick="pageTracker._trackPageview(&#39;outbound/petnoteslinks&#39;);" target="_blank"> www.aussiebcrescue.com/adoptapp.htm</a> to submit an adoption application.</strong></em><br /><br /><p><em><strong> We have many wonderful Aussies and Border Collies awaiting adoptive homes. Please visit our website <a href="http://aussiebcrescue.com/index.htm" onclick="pageTracker._trackPageview(&#39;outbound/petnoteslinks&#39;);" target="_blank"> www.AussieBCrescue.com</a> to view all of our available dogs.</strong></em></div>
<br/><a href="http://www.petfinder.com/petdetail/16966565">View this pet on Petfinder.com</a>

- <media>
- <photos>
  <photo id="1" size="x">http://photocache.petfinder.com/fotos/NV83/NV83.16966565-1-x.jpg</photo> 
  <photo id="1" size="t">http://photocache.petfinder.com/fotos/NV83/NV83.16966565-1-t.jpg</photo> 
  <photo id="1" size="pn">http://photocache.petfinder.com/fotos/NV83/NV83.16966565-1-pn.jpg</photo> 
  <photo id="1" size="pnt">http://photocache.petfinder.com/fotos/NV83/NV83.16966565-1-pnt.jpg</photo> 
  <photo id="1" size="fpm">http://photocache.petfinder.com/fotos/NV83/NV83.16966565-1-fpm.jpg</photo> 

Open in new window

Watch Question

Top Expert 2011

U can use cUrl to fetch the xml in  PHP and then use simplexml_load_string to parse the xml into an xml object.


Thank you Rik-Legger.....can you be a little more specific as to how I would do this or point me in the direction of a document that explains it? I've never done it before but I'm sure I can learn how with the proper documentation or examples. Thanks!
Top Expert 2011
Unlock this solution and get a sample of our free trial.
(No credit card required)


Okay, after further reviewing what I'd like to do here, I'm not sure that PHP is necessary and looks like it's getting a little more complicated than I would like......

Rather than using PHP, what I'd like to do is create an XSLT page with an XML stylesheet and then pass a URL to that XSLT file based on a couple of options that I give people. I think I'm going to close this question and create a separate question that's specific to XSLT. Thank you for the help, I'll definitely award points for your assistance.....
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.