【发布时间】:2020-02-05 23:55:13
【问题描述】:
我正在使用 CakePHP 框架并使用 HttpClient(cakephp) 获取响应。我尝试将 xml 转换为 php,但它在使用此函数 SimpleXMLElement() 时返回空对象
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:body>
<getaccountbalanceresponse xmlns="http://PegPayTelecomsApi/">
<getaccountbalanceresult>
<balance>xxx</balance>
<statusdesc>xxxx</statusdesc>
<statuscode>xxxx</statuscode>
</getaccountbalanceresult>
</getaccountbalanceresponse>
</soap:body>
如何将 xml 转换为 php。任何人都可以帮助我..
我的php代码是
$this->client = new Client();
$this->response->statusCode(200);
$this->RequestHeader = [
'headers' => [
'cache-control' => 'no-cache',
'content-type' => 'text/xml',
],
'ssl_verify_peer' => false,
'ssl_verify_host' => false,
'ssl_verify_peer_name' => false,
];
$this->OAuthUrl = 'https://test.pegasus.co.ug:8019/pegpaytelecomsapi/PegPayTelecomsApi.asmx';
$this->RequestAccessBody = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetAccountBalance xmlns="http://PegPayTelecomsApi/">
<vendorcode>CCCCC</vendorcode>
<password>RRRRRRR</password>
</GetAccountBalance>
</Body>
';
$response = $this->client->post($this->OAuthUrl,$this->RequestAccessBody,$this->RequestHeader);
$soap = simplexml_load_string($response->body);
【问题讨论】:
-
xml 到 php ??? CakePHP 版本???添加您的 PHP 代码。
-
是的兄弟..版本是3.5
-
不要在评论中添加代码,更新你的问题!
-
并阅读如何将 XML 转换为数组 book.cakephp.org/3/en/core-libraries/…
-
能否为问题添加一些示例代码
标签: php xml cakephp xml-parsing xmlhttprequest