duanji1610 2012-06-23 02:24
浏览 43
已采纳

无法使用SimpleXMLElement解析XML

For the life of me I can't figure out why I can't access any of the properties (or even figure out what they are) in this soap packet. I can't use anything that Mercury is returning to me. I have read through several other similar questions with no luck. I am sure this is just a product of my ignorance, but any help would be way appreciated.

$transactionInfo = new MercuryPaymentHandler($paymentID);
$returnValue = $transactionInfo->verifyPayment();
$xml = new SimpleXMLElement($returnValue);
var_dump(get_object_vars($xml));

returns:

array(0) { }

But this:

$transactionInfo = new MercuryPaymentHandler($paymentID);
$returnValue = $transactionInfo->verifyPayment();
$xml = new SimpleXMLElement($returnValue);
echo $xml->asXML();

returns:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <VerifyPaymentResponse xmlns="http://www.mercurypay.com/">
        <VerifyPaymentResult>
            <ResponseCode>0</ResponseCode>
            <Status>Approved</Status>
            <StatusMessage>AP</StatusMessage>
            <DisplayMessage>Your transaction has been approved.</DisplayMessage>               
            <AvsResult/>
            <CvvResult>M</CvvResult>
            <AuthCode>000027</AuthCode>
            <Token>ItIu8ayb9ZyMcBjHUkyHS0krnFVf6esnfs6tULuAo2giERIQACMQAgyc</Token>
            <RefNo>0028</RefNo>
            <Invoice>48</Invoice>
            <AcqRefData>KbMCC2110080622 </AcqRefData>
            <CardType>M/C</CardType><MaskedAccount>xxxxxxxx6781</MaskedAccount>
            <Amount>7</Amount>
            <TaxAmount>0</TaxAmount>
            <TransPostTime>2012-06-22T21:10:08.65</TransPostTime>
            <CardholderName>Test-User</CardholderName>
            <AVSAddress/>
            <AVSZip/>
            <TranType>Sale</TranType>
            <PaymentIDExpired>true</PaymentIDExpired>
            <CustomerCode/>
            <Memo>Mighty Wash 2.0</Memo>
            <AuthAmount>7</AuthAmount>
            <VoiceAuthCode/>
            <ProcessData>|00|600550672000</ProcessData>
            <OperatorID/>
            <TerminalName/>
        </VerifyPaymentResult>
        </VerifyPaymentResponse>
    </soap:Body>
</soap:Envelope>

What gives?

Update

I never figured this out using PHPs native class, but it was way easy with CakePHPs XML class.

  • 写回答

2条回答 默认 最新

  • dsewbh5588 2012-06-23 02:32
    关注

    The problem is that, internally, SimpleXMLElement is not stored as a trivial object. Basically, you have to know what properties to access and it composes the result on the fly from its internal structures. In your case, you could use something like this: http://php.net/manual/en/simplexmlelement.xpath.php (see the examples) to extract data efficiently. Also, to strictly answer your question, here is what you could use: http://www.php.net/manual/en/simplexmlelement.attributes.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测