PHP:XML解析问题

时间:2011-04-10 04:29:49

标签: php xml

我正在尝试创建一个与eWay集成的支付系统..他们提供了一些处理付款的代码,除非我运行它时遇到以下错误:

  

消息:未定义索引:值

     

行号:106

第106行引用的函数如下:

    function parseResponse($xmlResponse){
    $xml_parser = xml_parser_create();
    xml_parse_into_struct($xml_parser, $xmlResponse, $xmlData, $index);
    $responseFields = array();
    foreach($xmlData as $xData)
        if($xData["level"] == 2)
            $responseFields[$xData["tag"]] = $xData["value"];
    return $responseFields;
    }

我真的坚持这个,我似乎无法让它发挥作用。

任何诊断这方面的帮助都很棒。

干杯,

我试图解析的XML如下

<ewaygateway>
<ewayCustomerID>87654321</ewayCustomerID>
<ewayTotalAmount>44000</ewayTotalAmount>
<ewayCardHoldersName>Testing Test</ewayCardHoldersName>
<ewayCardNumber>4444333322221111</ewayCardNumber>
<ewayCardExpiryMonth>04</ewayCardExpiryMonth>
<ewayCardExpiryYear>15</ewayCardExpiryYear>
<ewayCustomerFirstName>Testing test</ewayCustomerFirstName>
<ewayCustomerLastName>Testing test</ewayCustomerLastName>
<ewayCustomerEmail>info@emailaddress.com.au</ewayCustomerEmail>
<ewayCustomerAddress>123 Testing St</ewayCustomerAddress>
<ewayCustomerPostcode>2000</ewayCustomerPostcode>
<ewayCustomerInvoiceDescription>Membership</ewayCustomerInvoiceDescription>
<ewayCustomerInvoiceRef>00001</ewayCustomerInvoiceRef>
<ewayTrxnNumber>000001</ewayTrxnNumber>
<ewayOption1>Nice</ewayOption1>
<ewayOption2>Big</ewayOption2>
<ewayOption3>Option</ewayOption3>
</ewaygateway>

此外,这是xml的生成方式

        $xmlRequest = "<ewaygateway><ewayCustomerID>" . $this->myCustomerID . "</ewayCustomerID>";
    foreach($this->myTransactionData as $key=>$value)
        $xmlRequest .= "<$key>$value</$key>";
    $xmlRequest .= "</ewaygateway>";

1 个答案:

答案 0 :(得分:1)

<ewaygateway>标记没有值。只需检查以确保isset存在值索引。