• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

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

how can i get information from XML web services in an API server using php

0
intazaar
Asked:
intazaar
1 Solution
 
soapergemCommented:
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
 
RoonaanCommented:
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now