2011-04-14 7 views
0

誰かが私にSimpleXMLオブジェクトに関する問題を助けてくれるかもしれません。SimpleXMLの問題

私はauthorize.net CIMマネージャーと統合し、顧客プロファイルを送信しています。私がそれを送ったとき、生のxmlレスポンスはパーサを通って渡され、SimpleXMLオブジェクトに変換されます。ここで

は、リクエストを送信するために使用されるコードです:

$content = 
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>". 
     "<createCustomerProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">". 
     MerchantAuthenticationBlock(). 
     "<profile>". 
     //"<merchantCustomerId>".$userInsertedId."</merchantCustomerId>". // Your own identifier for the customer. 
     "<description>'New User Purchase'</description>". 
     "<email>" . $_GET["email"] . "</email>". 
     "<paymentProfiles>". 
     "<billTo>". 
     "<firstName>".$_GET["firstname"]."</firstName>". 
     "<lastName>".$_GET["lastname"]."</lastName>". 
     "<address>".$_GET["street"]."</address>". 
     "<city>".$_GET["city"]."</city>". 
     "<state>".$_GET["state"]."</state>". 
     "<zip>".$_GET["zip"]."</zip>". 
     "<country>".$_GET["country"]."</country>". 
     "<phoneNumber>".$_GET["phone"]."</phoneNumber>". 
     "</billTo>". 
     "<payment>". 
     "<creditCard>". 
      "<cardNumber>".$_GET["number"]."</cardNumber>". 
      "<expirationDate>".$_GET["year"]."-".$_GET["month"]."</expirationDate>". // required format for API is YYYY-MM 
      "<cardCode>".$_GET["code"]."</cardCode>". 
     "</creditCard>". 
     "</payment>". 
     "</paymentProfiles>". 
     "</profile>". 
     "<validationMode>testMode</validationMode>". 
     "</createCustomerProfileRequest>"; 

     $CCresponse = send_xml_request($content); 

     //echo($CCresponse); 

     $parsedresponse = parse_api_response($CCresponse); 

    function parse_api_response($content) 
     { 
      $parsedresponse = simplexml_load_string($content, "SimpleXMLElement", LIBXML_NOWARNING); 
      if ("Ok" != $parsedresponse->messages->resultCode) 
      { 
       echo "The operation failed with the following errors:<br>"; 
       foreach ($parsedresponse->messages->message as $msg) 
       { 
        echo "[" . htmlspecialchars($msg->code) . "] " . htmlspecialchars($msg->text) . "<br>"; 
       } 
        echo "<br>"; 
      } 
      return $parsedresponse; 
     } 

私は次の操作を実行した場合:だから

SimpleXMLElement Object 
(
[messages] => SimpleXMLElement Object 
    (
     [resultCode] => Ok 
     [message] => SimpleXMLElement Object 
      (
       [code] => I00001 
       [text] => Successful. 
      ) 
    ) 
[customerProfileId] => 15642446 
[customerPaymentProfileIdList] => SimpleXMLElement Object 
    (
     [numericString] => 13865552 
    ) 
[customerShippingAddressIdList] => SimpleXMLElement Object 
    (
    ) 
[validationDirectResponseList] => SimpleXMLElement Object 
    (
     [string] => 1|1|1|(TESTMODE) This transaction has been approved.|000000|P|0|none|Test transaction for ValidateCustomerPaymentProfile.|1.00|CC|auth_only||*****|******||****|*******|******|******|USA|1234567890||[email protected]|none|none|none|none|none|none|none|none|0.00|0.00|0.00|FALSE|none|207BCBBF78E85CF174C87AE286B472D2|||||||||||||*******|*******|||||||||||||||| 
    ) 
) 
) 
) 

$parsedresponse = parse_api_response($CCresponse); 
print_r($parsedresponse); 

私は次の出力を得ますこれはすべてが働いているような外観です。私がしようとSimpleXMLオブジェクトをドリルダウンし、やるときには、この:私は「OkOk」の出力を取得しています

echo $code = (string) $parsedresponse->messages->resultCode; 

それは二度にわたり実行されているように、それはそうです。これは私を絶対に夢中にさせてくれて、ここで何が起こっているのか分かりません。誰かがここに正しい方向を向けるようにしてもらえますか?

ありがとうございます!

+1

この理由は、あなたのコード内の別の場所である可能性があります。あなたは '$ code'で何をしていますか? –

+0

何もない、私はちょうどそれをエコーするためにその変数を作成しました。 – ackerchez

+0

@ackerchezあなたは完全なコードを表示できますか? –

答えて

-1

たぶん、あなたは試してみて、このようにSimpleXMLElementをナビゲートするためのxpathメソッドを使用することができます。

$code = (string) $parsedresponse->xpath('messages/resultCode'); 
echo $code; 
+0

これは "Array"をエコーし​​ます – Gordon

+0

これは動作しません、単に "ArrayArray" – ackerchez

関連する問題