2009-06-26 79 views
1

嘿,所以我正在部署使用this function的運費計算器,並且僅在使用IE時纔會出現此錯誤。運費計算器對Firefox來說確實很好。我不熟悉這個錯誤,谷歌搜索告訴我這是xml格式的問題。問題是:來自UPS運輸計算服務器的XML響應不應包含此內容。 所以,我的問題是:您認爲該錯誤在哪裏?我很感謝在哪裏檢查的答案和建議。我正在畫空白。php,xml,ups shipping:「無法使用XSL查看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> --> 

想法?

+0

所以,事實證明,這是頁面,這是一個問題,意見不正確。 <!----------------------- main content -------------------> 在某些方面顯然是非法的,只能用於ie。現在我的問題是,頁面顯示的是html代碼,而不是呈現的html。 – montooner 2009-06-26 22:20:24

+0

不需要爲標題添加「[已解決]」,只需點擊回答的勾選標記即可接受答案(甚至可以是您自己的答案)。 – VolkerK 2009-06-27 10:03:34

回答

4

從技術上講,XML註釋中不能包含' - '。所以,你應該改變:

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

<!--     main content      --> 

...或者類似的東西。如果UPS正在發送它。您可以在將其轉發給瀏覽器之前進行替換。

編輯

關於顯示標記,而不是渲染HTML:如果你看到同樣的事情,在Firefox(< RatingServiceSelectionResponse等),這不是HTML - 這是XML。您可能希望使用XSLT進行轉換,或使用XPath(或XQuery等)從其中提取特定值。看起來你也可以使用你引用的ups-php API中的$ myRate-> getRate()函數。

1

問題是html格式不好。我刪除了我的所有評論,出於某種原因,現在它運行得更好。