PHP、XML、UPS发货:“无法使用XSL查看XML输入...”错误在哪里?

liwlm1x9  于 2023-01-12  发布在  PHP
关注(0)|答案(2)|浏览(129)

所以我使用this function部署了一个运费计算器,只有在我使用IE时才收到这个错误。Firefox对运费计算器做得很好。我不熟悉这个错误,谷歌搜索告诉我这是xml格式的问题。问题是:来自UPS的运费计算服务器的XML响应不应包含此内容。**因此,我的问题是:你认为错误在哪里?我很感激你的回答和建议。**我一片空白。
使用IE时出错(vrs 8.7和6):
无法显示XML页无法使用XSL样式表查看XML输入。请更正错误,然后单击“刷新”按钮,或稍后重试。
注解中使用了不正确的语法。处理资源“http:mgxvideo.com/mgxcopy-alpha-3/shopping/cart_displa...”时出错

<!------------------- main content ------------------------->
  • ————————-^
    从服务器请求的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> -->

想法?

3qpi33ja

3qpi33ja1#

从技术上讲,XML注解中不能有'--',所以应该更改:

<!------------------- main content ------------------------->

<!--                  main content                     -->

...或类似的内容。如果UPS正在发送邮件。您可以在将邮件转发到浏览器之前将其替换。
编辑
关于显示标记而不是呈现的HTML:如果你在Firefox中看到了相同的东西(〈RatingServiceSelectionResponse,等等),那不是HTML--而是XML。你要么想用XSLT转换它,要么想用XPath(或XQuery,等等)从中提取特定的值。看起来你也可以使用你引用的ups-php API中的$myRate-〉getRate()函数。

dnph8jn4

dnph8jn42#

这个问题是糟糕的html格式。我删除了所有的评论,由于某种原因,它现在工作得更好了。

相关问题