Re: Newbie Question - Parse XML with PHP...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Apr 19, 2013 at 4:04 PM, dealTek <dealtek@xxxxxxxxx> wrote:
>
> On Apr 19, 2013, at 1:33 PM, Sebastian Krebs <krebs.seb@xxxxxxxxx> wrote:
>
>> A "webpage" is a file, that (usually) a browser downloads and parses. You'll do exactly the same :-) I don't know exactly, but you can try to pass the URL directly to simplexml_load_file(). If this doesn't work, download the content (for example with file_get_contents()) and pass it to simplexml_load_string(). There are obviously many other approaches, but you should now have an idea :-)
>>
>
> Thanks Sebastian for the help....
>
> Actually what is happening in my case is:
>
> page1.php is sending out to credit card company - getting processed - then coming back to the *same page1.php* with the XML data listed below...

Please expand what you mean by "sending out" and "coming back" - is
this a REST or SOAP API call? In that case, the response body is
likely to be the XML.

>
> - so I'm not going to some other page to get it - it is coming to me to the same page I am on..........
>
> so - after the XML result comes in - I need to assign the php to the XML somehow...

How do you recognize the "XML result com(ing) in" ?



>
> I hope I am making myself clear....
>
> Thanks in advance for the help
>
>
>> Or you use a specialized library like Guzzle.
>>
>> Am 19.04.2013 22:17 schrieb "dealTek" <dealtek@xxxxxxxxx>:
>> Hi all,
>>
>> newbie - just starting with trying to parse XML...
>>
>>
>> $mylist = simplexml_load_file('thelist.xml');
>>
>> then use a foreach to echo the data...
>>
>> <?php
>>     $mysongs = simplexml_load_file('songs.xml');
>>
>>     foreach ($mysongs as $songinfo) {
>>         $title=$songinfo->title;
>>         $artist=$songinfo->artist;
>>         $date=$songinfo['dateplayed'];
>>         echo $title.' --- ';
>>                 echo $artist.' --- ';
>>                 echo $date.' --- ';
>>                 echo ' </br> ';
>>         }
>>
>> ?>
>>
>> that I get ...
>>
>> Question: how do you use $mylist when the xml is not as a file but is returned on a web page?
>>
>>
>> an example of the real xml I am trying to work with is like this demo below ....
>>
>> Goal : when this response comes back - I would like to be able to get the data as php and then update the database....
>>
>>
>> example........
>> <?xml version="1.0" encoding="UTF-8"?>
>> <response>
>>   <result>1</result>
>>   <result-text>SUCCESS</result-text>
>>   <transaction-id>1865264174</transaction-id>
>>   <result-code>100</result-code>
>>   <authorization-code>123456</authorization-code>
>>   <avs-result>N</avs-result>
>>   <cvv-result>N</cvv-result>
>>   <action-type>sale</action-type>
>>   <amount>12.00</amount>
>>   <ip-address>::1</ip-address>
>>   <industry>ecommerce</industry>
>>   <processor-id>ccprocessora</processor-id>
>>   <currency>USD</currency>
>>   <order-description>Small Order</order-description>
>>   <merchant-defined-field-1>Red</merchant-defined-field-1>
>>   <merchant-defined-field-2>Medium</merchant-defined-field-2>
>>   <order-id>1234</order-id>
>>   <tax-amount>2.00</tax-amount>
>>   <shipping-amount>0.00</shipping-amount>
>>   <billing>
>>     <first-name>John</first-name>
>>     <last-name>Smith</last-name>
>>     <address1>1234 Main St.</address1>
>>     <city>Beverly Hills</city>
>>     <state>CA</state>
>>     <postal>90210</postal>
>>     <country>US</country>
>>     <phone>555-555-5555</phone>
>>     <email>test@xxxxxxxxxxx</email>
>>     <company>Acme, Inc.</company>
>>     <cc-number>400000******0002</cc-number>
>>     <cc-exp>0118</cc-exp>
>>   </billing>
>>   <shipping>
>>     <first-name>Mary</first-name>
>>     <last-name>Smith</last-name>
>>     <address1>1234 Main St.</address1>
>>     <city>Beverly Hills</city>
>>     <state>CA</state>
>>     <postal>90210</postal>
>>     <country>US</country>
>>     <address2>Unit #2</address2>
>>   </shipping>
>>   <product>
>>     <product-code>SKU-123456</product-code>
>>     <description>test product description</description>
>>     <commodity-code>abc</commodity-code>
>>     <unit-of-measure>1</unit-of-measure>
>>     <unit-cost>5.0000</unit-cost>
>>     <quantity>1.0000</quantity>
>>     <total-amount>7.00</total-amount>
>>     <tax-amount>2.00</tax-amount>
>>     <tax-rate>1.00</tax-rate>
>>     <discount-amount>2.00</discount-amount>
>>     <discount-rate>1.00</discount-rate>
>>     <tax-type>sales</tax-type>
>>     <alternate-tax-id>12345</alternate-tax-id>
>>   </product>
>>   <product>
>>     <product-code>SKU-123456</product-code>
>>     <description>test 2 product description</description>
>>     <commodity-code>abc</commodity-code>
>>     <unit-of-measure>2</unit-of-measure>
>>     <unit-cost>2.5000</unit-cost>
>>     <quantity>2.0000</quantity>
>>     <total-amount>7.00</total-amount>
>>     <tax-amount>2.00</tax-amount>
>>     <tax-rate>1.00</tax-rate>
>>     <discount-amount>2.00</discount-amount>
>>     <discount-rate>1.00</discount-rate>
>>     <tax-type>sales</tax-type>
>>     <alternate-tax-id>12345</alternate-tax-id>
>>   </product>
>> </response>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> Thanks,
>> Dave - DealTek
>> dealtek@xxxxxxxxx
>> [db-3]
>>
>
>
> --
> Thanks,
> Dave - DealTek
> dealtek@xxxxxxxxx
> [db-3]
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux