Solved

using php to get information from XML web services in an API server

Posted on 2006-10-29
2
283 Views
Last Modified: 2006-11-18
how can i get information from XML web services in an API server using php

0
Comment
Question by:intazaar
2 Comments
 
LVL 6

Accepted Solution

by:
soapergem earned 500 total points
ID: 17832088
If you're familiar with SOAP (Simple Object Access Protocol), it is supported in PHP5. I'm not really familiar with it myself, but I know it goes hand-in-hand with many web services.
http://www.php.net/soap

Also in PHP5, there are some functions to parse the XML response using the SimpleXML extension.
http://www.php.net/simplexml

I'm still using PHP4, myself, so what I generally do is to use the file_get_contents() function, which accepts a URL parameter, to retrieve the API responses. I usually just write regular expressions to grab the data I'm interested in, but there's also a built-in XML parser, but it is a little different from the one in PHP5. Assuming you have the XML response in $data, you could execute code like this to parse it:

    $data = file_get_contents('http://www.web.services.com/service?api_key=123456');
   
    $parser = xml_parser_create('UTF-8');
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $vals, $index);
    xml_parser_free($parser);

http://www.php.net/xml-parser-create
http://www.php.net/file-get-contents
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 17835804
In php4 you can also use the xml_unserialize by Keith Devens. It converts an xml message into an array and vice versa.

-r-
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 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