php,xml,ups Shipping:“无法使用 XSL 查看 XML 输入...” 错误在哪里?
所以我使用此函数部署运费计算器,我得到仅当我使用 IE 时出现此错误。 Firefox 的运费计算器做得很好。 我对这个错误不熟悉,google搜索告诉我这是xml格式的问题。 问题是:来自 UPS 运输计算服务器的 XML 响应不应包含此内容。 所以,我的问题是:你认为 bug 出在哪里? 我很欣赏关于在哪里检查的答案和建议。我现在一片空白。
使用 IE 时出错(vrs 8、7 和 6):
无法显示 XML 页面 无法使用 XSL 样式查看 XML 输入 床单。 请更正错误并 然后单击“刷新”按钮,或尝试 稍后再来。
<小时>在 a 中使用了不正确的语法 评论。 处理资源时出错 'http://mgxvideo.com/mgxcopy-alpha-3/shopping/cart_displa...
----------^
从服务器请求的部分 php 代码:
$ch = curl_init("https://www.ups.com/ups.app/xml/Rate");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_TIMEOUT, 90);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$result=curl_exec ($ch);
echo '<!-- '. $result. ' -->'; // THIS LINE IS FOR DEBUG PURPOSES ONLY-IT WILL SHOW IN HTML COMMENTS
$data = strstr($result, '<?');
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
eval($php_stmt);
}
}
curl_close($ch);
#print_r($params);
#echo "<br/><br/>";
return $params['RATINGSERVICESELECTIONRESPONSE']['RATEDSHIPMENT']['TOTALCHARGES']['MONETARYVALUE'];
以下是 Firefox 回显的结果来自 xml 请求(在上面的代码中,这是一行“此行仅用于调试目的”:
<!-- HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Fri, 26 Jun 2009 21:58:04 GMT
Server: Apache
Pragma: no-cache
Content-Length: 1524
Content-Type: application/xml
<?xml version="1.0"?><RatingServiceSelectionResponse><Response><TransactionReference><CustomerContext>Bare Bones Rate Request</CustomerContext><XpciVersion>1.0</XpciVersion></TransactionReference><ResponseStatusCode>1</ResponseStatusCode><ResponseStatusDescription>Success</ResponseStatusDescription></Response><RatedShipment><Service><Code>02</Code></Service><RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>6.0</Weight></BillingWeight><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>14.34</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>14.34</MonetaryValue></TotalCharges><GuaranteedDaysToDelivery>2</GuaranteedDaysToDelivery><ScheduledDeliveryTime></ScheduledDeliveryTime><RatedPackage><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>14.34</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>14.34</MonetaryValue></TotalCharges><Weight>6.0</Weight><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>6.0</Weight></BillingWeight></RatedPackage></RatedShipment></RatingServiceSelectionResponse> -->
有想法吗?
so I'm deploying a shipping calculator using this function, and I'm getting this error only when I use IE. Firefox does just fine with the shipping calculator. I'm unfamiliar with this error, and google searches tell me that it's a problem with the xml format. Problem is: the XML response from UPS's shipping calculation server shouldn't have this content. So, my question is: where do you think the bug is? I appreciate answers and suggestions of where to check. I'm drawing a blank.
Error when using IE (vrs 8. 7, and 6):
The XML page cannot be displayed
Cannot view XML input using XSL style
sheet. Please correct the error and
then click the Refresh button, or try
again later.Incorrect syntax was used in a
comment. Error processing resource
'http://mgxvideo.com/mgxcopy-alpha-3/shopping/cart_displa...<!------------------- main content ------------------------->
----------^
Portion of the php code requesting from the server:
$ch = curl_init("https://www.ups.com/ups.app/xml/Rate");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_TIMEOUT, 90);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$result=curl_exec ($ch);
echo '<!-- '. $result. ' -->'; // THIS LINE IS FOR DEBUG PURPOSES ONLY-IT WILL SHOW IN HTML COMMENTS
$data = strstr($result, '<?');
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
eval($php_stmt);
}
}
curl_close($ch);
#print_r($params);
#echo "<br/><br/>";
return $params['RATINGSERVICESELECTIONRESPONSE']['RATEDSHIPMENT']['TOTALCHARGES']['MONETARYVALUE'];
And here's what Firefox echoes as the result from the xml request (in the above code, it's the line that says "THIS LINE IS FOR DEBUG PURPOSES ONLY":
<!-- HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Fri, 26 Jun 2009 21:58:04 GMT
Server: Apache
Pragma: no-cache
Content-Length: 1524
Content-Type: application/xml
<?xml version="1.0"?><RatingServiceSelectionResponse><Response><TransactionReference><CustomerContext>Bare Bones Rate Request</CustomerContext><XpciVersion>1.0</XpciVersion></TransactionReference><ResponseStatusCode>1</ResponseStatusCode><ResponseStatusDescription>Success</ResponseStatusDescription></Response><RatedShipment><Service><Code>02</Code></Service><RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>6.0</Weight></BillingWeight><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>14.34</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>14.34</MonetaryValue></TotalCharges><GuaranteedDaysToDelivery>2</GuaranteedDaysToDelivery><ScheduledDeliveryTime></ScheduledDeliveryTime><RatedPackage><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>14.34</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>14.34</MonetaryValue></TotalCharges><Weight>6.0</Weight><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>6.0</Weight></BillingWeight></RatedPackage></RatedShipment></RatingServiceSelectionResponse> -->
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从技术上讲,XML 注释中不能包含“--”。 所以你应该改变:
到
...或类似的东西。 如果 UPS 正在发送。 您可以在将其转发到浏览器之前替换它。
编辑
关于显示标记而不是呈现的 HTML:如果您看到与 Firefox 中相同的内容(getRate() 函数。
Technically, you can't have '--' inside of XML comments. So you should change:
to
...or something similar. If UPS is sending it. You can replace it before you forward it to the browser.
EDIT
Regarding displaying the markup rather than rendered HTML: If you're seeing the same thing as in Firefox (<RatingServiceSelectionResponse, etc.) that's not HTML--it's XML. You'll either want to transform it with XSLT or use XPath (or XQuery, etc.) to fetch particular values out of it. Looks like you could also use the $myRate->getRate() function from ups-php API you referenced.
问题是 html 格式不佳。 我删除了所有评论,出于某种原因,它现在工作得更好了。
the issue was poor html formatting. I deleted all my comments, and for some reason it's working better now.