运行下面的代码时,出现以下错误:
未能在标记请求行 2 中加载 XML 数据过早结束
致命错误:在第 61 行的 /home4/viptrav3/public_html/wp-content/themes/voyage-child/transfer.php 中的非对象上调用成员函数 asXml()
第 61 行是$requestFile->asXml('trequest.xml');
但我没有看到 XML 过早关闭。我想将此保存为 XML 文件 trequest.xml
//Build XML Request
$requestData = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
$requestData .= '<Request>';
// Create Request Header
$requestData .= '<Source>';
// Add Requestor ID data
$requestData .= '<RequestorID Client="' . $clientID . '" EMailAddress="' . $email . '" Password="' . $password . '" />';
// Add Requestor Preferences data
$requestData .= '<RequestorPreferences Language="' . $language . '" Currency="USD" Country="US" >';
$requestData .= '<RequestMode>' . $requestMode . '</RequestMode>';
$requestData .= '</RequestorPreferences>';
$requestData .= '</Source>';
// Create Request Body
$requestData .= '<RequestDetails>
<SearchTransferPriceRequest>
<TransferPickUp>
<PickUpCityCode>LON</PickUpCityCode>
<PickUpCode>A</PickUpCode>
<PickUpPointCode>LCY</PickUpPointCode>
</TransferPickUp>
<TransferDropOff>
<DropOffCityCode>EDI</DropOffCityCode>
<DropOffCode>H</DropOffCode>
</TransferDropOff>
<TransferDate>
2013-11-11</TransferDate>
<NumberOfPassengers>2</NumberOfPassengers>
<PreferredLanguage>E</PreferredLanguage>
</SearchTransferPriceRequest>
</RequestDetails>';
//Save Request & Display XML errors
libxml_use_internal_errors(true);
$sxe = simplexml_load_string($requestData);
if ($sxe === false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
$requestFile = simplexml_load_string($requestData);
$requestFile->asXml('trequest.xml');