Solved

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

Posted on 2006-10-29
2
281 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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…
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…
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 …

914 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

21 Experts available now in Live!

Get 1:1 Help Now