Tek bir dize sonucunu almak için SimpleXMLElement üzerinde XPath kullanarak

0 Cevap

Ben bir GoogleCheckout tepki bazı verileri almak için çalışıyorum. Ben veri aramak için bir SimpleXMLElement ve XPath'i kullanıyorum. Sorunlardan biri xpath gelen yanıt SimpleXMLElement bir dizi olmasıdır - Ben istiyorum tüm dize veridir. Örneğin, <email> en az iki kez gösterilen ama sadece bir ateşten sonuç istiyorsun - Diğer tepkisi TAG adı multilpe örneğini içerebilir olmasıdır.

İşte ben bugüne kadar ne var

            $notifyData = array();
            $notifyData['buyerEmail'] = $data->xpath('buyer-billing-address//email')[0];
            $notifyData['buyerName'] = $data->xpath('buyer-billing-address//contact-name');
            $notifyData['transactionId'] = $data->xpath('/new-order-notification/google-order-number');
            $notifyData['itemName'] = $data->xpath('//item-name');
            $notifyData['amount'] = $data->xpath('//unit-price');
            $notifyData['currency'] = $notifyData['amount'][0]['currency'];//$data->xpath('//@currency[1]');

Burada $ notifyData üzerindeki print_r gelen yanıt () olduğunu

Array
(
    [buyerEmail] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => sandbox@mysite.com
                )

        )

    [buyerName] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => Mr Sandbox Buyer
                )

        )

    [transactionId] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => 271578474675716
                )

        )

    [itemName] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => My Item
                )

        )

    [amount] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [currency] => USD
                        )

                    [0] => 3.99
                )

        )

    [currency] => SimpleXMLElement Object
        (
            [0] => USD
        )

)

Veri print_r sonra bu gibi göstermek () için ne i istiyorum

Array
(
    [buyerEmail] => sandbox@mysite.com
    ...
    [currency] => USD

Burada, bir XML yanıt örneğidir

<new-order-notification xmlns="http://checkout.google.com/schema/2" serial-number="654578974677716-00001-7">

  <buyer-billing-address>

    <address1>19 sandbox st</address1>

    <address2></address2>

    <phone></phone>

    <email>sandbox@mysite.com</email>

    <company-name></company-name>

    <contact-name>Mr Sandbox Buyer</contact-name>

    <fax></fax>

    <country-code>AU</country-code>

    <city>Buyers Town</city>

    <region>VIC</region>

    <postal-code>3460</postal-code>

  </buyer-billing-address>

  <timestamp>2010-10-24T04:25:41.723Z</timestamp>

  <google-order-number>298578974677716</google-order-number>

  <shopping-cart>

    <items>

      <item>

        <digital-content>

          <key is-encrypted="true">PWWoqHo+FtfTi5vHmquOFTFNb4DwNjInAxkW89PLxtU=</key>

          <description>Follow the instructions</description>

          <url>http://mysite.com</url>

        </digital-content>

        <item-name>my product</item-name>

        <item-description>my product</item-description>

        <unit-price currency="USD">3.99</unit-price>

        <quantity>1</quantity>

      </item>

    </items>

  </shopping-cart>

  <order-adjustment>

    <merchant-codes />

    <total-tax currency="USD">0.0</total-tax>

    <adjustment-total currency="USD">0.0</adjustment-total>

  </order-adjustment>

  <buyer-id>634168749882822</buyer-id>

  <buyer-marketing-preferences>

    <email-allowed>true</email-allowed>

  </buyer-marketing-preferences>

  <buyer-shipping-address>

    <address1>19 sandbox st</address1>

    <address2></address2>

    <phone></phone>

    <email>sandbox@mysite.com</email>

    <company-name></company-name>

    <contact-name>Mr Sandbox Buyer</contact-name>

    <fax></fax>

    <country-code>AU</country-code>

    <city>Buyers Town</city>

    <region>VIC</region>

    <postal-code>3460</postal-code>

  </buyer-shipping-address>

  <order-total currency="USD">3.99</order-total>

  <fulfillment-order-state>NEW</fulfillment-order-state>

  <financial-order-state>REVIEWING</financial-order-state>

</new-order-notification>

0 Cevap