【发布时间】:2016-05-26 16:24:19
【问题描述】:
我正在尝试从这个 XML ($xml) 中打印一个值,我尝试了每一种方法来做到这一点,但没有。
我正在使用 ASMX Web 服务,因此我必须将对象响应解析为 XML,并使用 XMLSerializer 来完成。
我只是想知道我在从整个 XML 中打印单个值时做错了什么。
这是我的代码:
require_once('nusoap/lib/nusoap.php');
require_once 'xmlserializer/XML/Serializer.php';
$client = new SoapClient('https://omegasandbox.megasys.net:444/Client/WebServices/CustomerPortal.asmx?WSDL');
$token = $client->Login(array('clientNumber' => 'xxx', 'userName' => 'xxxxxx', 'password' => 'xxxxxxx'));
echo '<br><br>';
$realtoken = $token->LoginResult;
$summary = $client->GetAccountSummary(array('token'=>$realtoken, 'accountNumber' => 1111));
$summary = json_encode($summary);
$data = json_decode($summary, true);
// An array of serializer options.
$serializer_options = array (
'addDecl' => TRUE,
'encoding' => 'ISO-8859-1',
'indent' => ' ',
'rootName' => 'json',
'mode' => 'simplexml'
);
$Serializer = &new XML_Serializer($serializer_options);
$status = $Serializer->serialize($data);
if (PEAR::isError($status)) {
die($status->getMessage());
}
$xml = $Serializer->getSerializedData();
echo "echo xml <br><br>";
echo $xml;
echo "<br><br>";
echo "echo xml2<br><br>";
echo $xml2 = htmlspecialchars_decode($xml);
希望你能帮助我,谢谢。
编辑:
最后我想出了最后一步。这是最终代码:
<?php
require_once('nusoap/lib/nusoap.php');
require_once 'xmlserializer/XML/Serializer.php';
$client = new SoapClient('https://omegasandbox.megasys.net:444/Client/WebServices/CustomerPortal.asmx?WSDL');
$token = $client->Login(array('clientNumber' => 'xxx', 'userName' => 'xxxxx', 'password' => 'xxxxxx'));
echo '<br><br>';
$realtoken = $token->LoginResult;
$summary = $client->GetAccountSummary(array('token'=>$realtoken, 'accountNumber' => 11111));
$summary = json_encode($summary);
$data = json_decode($summary, true);
// An array of serializer options.
$serializer_options = array (
'addDecl' => TRUE,
'encoding' => 'ISO-8859-1',
'indent' => ' ',
'rootName' => 'json',
'mode' => 'simplexml'
);
$Serializer = &new XML_Serializer($serializer_options);
$status = $Serializer->serialize($data);
if (PEAR::isError($status)) {
die($status->getMessage());
}
$xml = $Serializer->getSerializedData();
ob_start();
echo $xml;
$data = ob_get_contents();
ob_end_clean();
$order = simplexml_load_string(htmlspecialchars_decode($data));
//This was the final step.
echo $order->GetAccountSummaryResult[0]->any[0]->GetAccountSummary[0]->LoanAmount;
?>
感谢@Rasclatt 的大力帮助。
【问题讨论】:
标签: php xml printing display serialization