當前位置:首頁 » 編程語言 » php接受xml

php接受xml

發布時間: 2025-07-15 05:51:04

php解析xml

.asmx的全程是ASMX Active Server Methods,.asmx 是WEB服務文件,asmx.cs里有相關代碼
屬於B/S形式,用SOAP方式HTTP訪問,用XML返回。

以下是 php語言 利用 soap調用.Net的WebService asmx文件

<?php
//php.ini中打開下面3個dll
//extension = php_soap.dll
//extension = php_curl.dll
//extension = php_openssl.dll
header("content-type:text/html;charset=utf-8");
$client = new SoapClient(" http://192.168.1.178:808/ChkWelePsw.asmx?WSDL");
//本行測試不可行 $client = new SoapClient(" http://192.168.1.178:808/chkwelepsw.asmx?WSDL/ChkWele?username=test3&psw=123");
//參數這樣傳遞 先包裝一下
$param = array('username'=>'test3','psw'=>'123');
//調用必須用__soapCall
$p = $client->__soapCall('ChkWele',array('parameters' => $param));
print_r($p->ChkWeleResult); //這里先輸出一下變數$p,看看是什麼類型。
?>

.NET部分 webservice要注意的地方
/*
* <system.web>在這個節點中加入如下內容
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>
*/
[WebMethod(Description = "This......", EnableSession = false)]
public string ChkWele(string username, string psw)
{
string ret = "";
return ret;
}

❷ PHP讀取xml文件

以前做過聯通或電信的service訂購介面,收到的內容就是XML的,需要用到PHP的XML處理功能,你的代碼可以這樣:
<xmp>
<?php

$string=file_get_contents("http://www.orderjiaju.com/zixun/data/rss/3.xml");
if($string!=""):
$xml = new DomDocument('1.0');
$xml->loadXML($string);

//班台
$BanTai=array(
'Title'=>$xml->getElementsByTagName('channel')->item(0)->childNodes->item(1)->nodeValue,
'Link' =>$xml->getElementsByTagName('channel')->item(0)->childNodes->item(3)->nodeValue
);

for($i=0;$i<3;$i++)
{
$Title[]=array(
'Title'=>$xml->getElementsByTagName('item')->item($i)->childNodes->item(1)->nodeValue,
'Link' =>$xml->getElementsByTagName('item')->item($i)->childNodes->item(3)->nodeValue
);
}

print_r($BanTai);
print_r($Title);
endif;
?>
</xmp>

回答補充:

現在你直接,然後執行沒效果嗎?
我這里是可以的呢,測試網址是:service.020i.net/test_xml.php

❸ php dom在讀取xml文件時,提示錯誤Warning: DOMDocument::load(): Start tag expected, '<' not found

沒有找到<符號。xml的格式一定有錯誤。
再讀到非法字元後也會影響之後的讀取,這時也可能彈出這類警告。
貼出抱錯周圍幾行的內容一看便知。

❹ PHP獲取xml中值的幾種方法簡單總結

php 中有個內置類可以用來操作XML, 簡單說下

$xmlData="<xml><name>來自上海</name></xml>";//xml數據

$doc=newDOMDocument();
$doc->loadXML($xmlData);//載入XML數據
$root=$doc->documentElement;//獲取根節點對象
$items=$root->getElementsByTagName('name');//獲取name節點

echo$items[0]->nodeValue;//輸出獲取到的所有節點中的第一個節點的值

foreach($itemsas$value){
echo$value->nodeValue;//輸出節點中的值
}

❺ PHP怎麼解析微信支付結果返回的xml

PHP解析微信支付結果返回的xml的方法是通過自定義方法和第三方組件DomDocument實現的。
1、解析代碼如下:
<?PHP
header("Content-type:text/html; Charset=utf-8");
$url = "http://www.google.com/ig/api?weather=shenzhen";

// 載入XML內容
$content = file_get_contents($url);
$content = get_utf8_string($content);
$dom = DOMDocument::loadXML($content);
/*
此處也可使用如下所示的代碼,
$dom = new DOMDocument();
$dom->load($url);
*/

$elements = $dom->getElementsByTagName("current_conditions");
$element = $elements->item(0);
$condition = get_google_xml_data($element, "condition");
$temp_c = get_google_xml_data($element, "temp_c");
echo '天氣:', $condition, '<br />';
echo '溫度:', $temp_c, '<br />';

function get_utf8_string($content) { // 將一些字元轉化成utf8格式
$encoding = mb_detect_encoding($content, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
return mb_convert_encoding($content, 'utf-8', $encoding);
}

function get_google_xml_data($element, $tagname) {
$tags = $element->getElementsByTagName($tagname); // 取得所有的$tagname
if ($items->length > 1) {
return $items;
}
$tag = $tags->item(0); // 獲取第一個以$tagname命名的標簽
if ($tag->hasAttributes()) { // 獲取data屬性
$attribute = $tag->getAttribute("data");
return $attribute;
}else {
return false;
}
}
?>
2、返回支付的xml報文:
<?xml version="1.0"?>
<xml_api_reply version="1">
<weather mole_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<forecast_information>
<city data="Shenzhen, Guangdong"/>
<postal_code data="shenzhen"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2009-10-05"/>
<current_date_time data="2009-10-04 05:02:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Sunny"/>
<temp_f data="88"/>
<temp_c data="31"/>
<humidity data="Humidity: 49%"/>
<icon data="/ig/images/weather/sunny.gif"/>
<wind_condition data="Wind: mph"/>
</current_conditions>
</weather>
</xml_api_reply>
3、列印解析結果:

print $html;

❻ php 解析xml 的方法

$url =「給你介面的路徑";
$doms = simplexml_load_file ( $url );//直接把路徑放在simplexml_load_file 方法里就行$doms里存放的就是讀取的 XML 信息,你可以print_r($doms)試一下
然後用循環你就可以獲得 XML裡面的信息了
foreach ( $doms->節點名字 as $studys )
{
echo $studys."</br>";//輸入一下結果可以看一下
}
注意:simplexml_load_file ( $url )這個方法解析出來的中文只能是utf-8 如果你的項目使用的不是該編碼會出現中文亂碼,你可以用
iconv ( "UTF-8", "GB2312", 「這里放你要轉換的內容」);轉換能你用的編碼格式例如轉換成GB2312

熱點內容
怎麼刪除配置提示 發布:2025-07-15 10:21:27 瀏覽:245
java深入學習 發布:2025-07-15 10:13:50 瀏覽:534
linux應用程序開發pdf 發布:2025-07-15 10:11:37 瀏覽:911
解壓冷知識 發布:2025-07-15 10:11:35 瀏覽:78
outlook郵件的伺服器是什麼 發布:2025-07-15 09:45:59 瀏覽:482
如何安排資產配置 發布:2025-07-15 09:33:24 瀏覽:906
更新傳送伺服器目的地址失敗 發布:2025-07-15 09:27:05 瀏覽:484
c語言else的用法 發布:2025-07-15 09:19:54 瀏覽:119
tnt蘋果核安卓怎麼加好友 發布:2025-07-15 09:05:15 瀏覽:239
年輕人運行內存為什麼比安卓好 發布:2025-07-15 08:52:03 瀏覽:515