php、xml、upsの配送:「XSL を使用して XML 入力を表示できません…」 どこにバグがあるのでしょうか?

StackOverflow https://stackoverflow.com/questions/1051492

質問

ねえ、私は次を使用して送料計算ツールをデプロイしています この機能, IEを使用している場合にのみこのエラーが発生します。Firefox は送料計算ツールをうまく機能させます。私はこのエラーには詳しくありませんが、Google で検索すると、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> -->

アイデアは?

役に立ちましたか?

解決

技術的には、XML コメント内に「--」を含めることはできません。したがって、次のように変更する必要があります。

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

<!--                  main content                     -->

...またはそれに似たもの。UPS が送信している場合。ブラウザに転送する前に置き換えることができます。

編集

レンダリングされた HTML ではなくマークアップの表示について:Firefox と同じもの (<RatingServiceSelectionResponse など) が表示される場合、それは HTML ではなく、XML です。XSLT で変換するか、XPath (または XQuery など) を使用して特定の値を取得する必要があります。参照したups-php APIの$myRate->getRate()関数も使用できるようです。

他のヒント

問題は貧弱な HTML フォーマットでした。コメントをすべて削除しましたが、何らかの理由で今は改善されました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top