xml的Web服务

前端之家收集整理的这篇文章主要介绍了xml的Web服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Web服务用的是SOAP(简单对象访问协议):是web服务的通信协议,用来定义返回信息的xml格式的规范

技术
后缀
Asp .asp
PHP .PHP
.net(跨语言) .aspx
java .jsp

Wsdl:web服务描述语言,包括一系列web服务的定义。

注意:PHP默认不支持soap协议的,要在PHP.ini中开启soap协议


重启服务器


PHP利用xml调用国际航班

<?PHP
echo '<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
$client = new SoapClient('http://ws.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl');
$city = $client->getDomesticCity()->getDomesticCityResult->any;
$simple = new SimpleXMLElement($city);

$addr_array = $simple->Airline1->Address;
?>
<form id="form1" name="form1" method="post" action="">
	出发城市:
	<select name="startCity" id="startCity">
		<?PHP
		foreach($addr_array as $row) :
		?>
			<option><?PHP echo $row->cnCityName; ?></option>
		<?PHP
		endforeach;
		?>
	</select>
	到达城市:
	<select name="lastCity" id="lastCity">
		<?PHP
		foreach($addr_array as $row) :
		?>
			<option><?PHP echo $row->cnCityName; ?></option>
		<?PHP
		endforeach;
		?>
	</select>
	时间:<input type="text" name="theDate" value="<?PHP echo date('Y-m-d'); ?>" />
	<input type="submit" name="button" id="button" value="提交" />
</form>
<?PHP
if(!empty($_POST)){
	$startCity = $_POST['startCity'];
	$lastCity = $_POST['lastCity'];
	$theDate = $_POST['theDate'];
	$param = array(
		'startCity'=>$startCity,'lastCity'=>$lastCity,'theDate'=>$theDate,'userId'=>''
	);
	$airline_str = $client->getDomesticAirlinesTime($param)->getDomesticAirlinesTimeResult->any;
	$simple = new SimpleXMLElement($airline_str);
	echo '<pre>';
	$airline_array = $simple->Airlines->AirlinesTime;
?>
<table width="780" border="1" bordercolor="#000000" align="center">
<tr>
	<th>航空公司</th>
	<th>航班</th>
	<th>出发机场</th>
	<th>到达机场</th>
	<th>起飞时间</th>
	<th>到达时间</th>
	<th>机型</th>
	<th>停靠站</th>
	<th>分型日期</th>
</tr>
<?PHP
foreach($airline_array as $airline) :	
?>
<tr>
	<th><?PHP echo $airline->Company; ?></th>
	<th><?PHP echo $airline->AirlineCode; ?></th>
	<th><?PHP echo $airline->StartDrome; ?></th>
	<th><?PHP echo $airline->ArriveDrome; ?></th>
	<th><?PHP echo $airline->StartTime; ?></th>
	<th><?PHP echo $airline->ArriveTime; ?></th>
	<th><?PHP echo $airline->Mode; ?></th>
	<th><?PHP echo $airline->AirlineStop; ?></th>
	<th><?PHP echo $airline->Week; ?></th>
</tr>
<?PHP
endforeach;
?>
</table>
<?PHP
}
?>

执行效果图:




PHP利用xml调用本地ip访问

<?PHP
echo '<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
$client = new SoapClient('http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl');
$Ip = $client->getGeoIPContext()->getGeoIPContextResult->string;
?>

<table width="780" border="1" bordercolor="#000000" align="center">
<tr>
	<th>网址</th>
</tr>
<?PHP
foreach($Ip as $ip) :	
?>
<tr>
	<th><?PHP echo $ip; ?></th>
</tr>
<?PHP
endforeach;
?>
</table>
<?PHP

执行效果图:

猜你在找的XML相关文章