【问题标题】:php,xml,ups shipping: "Cannot view XML input using XSL..." Where's the bug?php,xml,ups shipping:“无法查看使用 XSL 的 XML 输入...”错误在哪里?
【发布时间】:2009-06-26 22:10:01
【问题描述】:

嘿,所以我正在使用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> -->

想法?

【问题讨论】:

  • 所以,原来是页面问题,cmets 没有正确完成。 显然是非法的以某种方式仅适用于即。现在我的问题是页面显示的是 html 代码而不是呈现的 html。
  • 无需在标题中添加“[已解决]”,只需单击答案的勾勒勾号即可接受答案(甚至可能是您自己的答案)。

标签: php xml internet-explorer xls shipping


【解决方案1】:

从技术上讲,您不能在 XML cmets 中使用“--”。所以你应该改变:

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

<!--                  main content                     -->

...或类似的东西。如果 UPS 正在发送它。您可以在转发到浏览器之前替换它。

编辑

关于显示标记而不是呈现 HTML:如果您在 Firefox 中看到相同的内容(getRate() 函数。

【讨论】:

  • srsly?谢谢你的评论。呈现的 html 似乎是 ie8 惩罚 html 中的语法错误的方式。它会呈现所有代码,直到您遇到语法错误,并在其中突出显示它并显示“div 标签与打开的 br 标签不匹配”。这个特定的错误被推迟了。 wtf br 标签不匹配,你知道吗?
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 2019-01-08
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    相关资源
    最近更新 更多