Note that there are some explanatory texts on larger screens.

plurals
  1. POparse xml with php using simplexml_load_string
    text
    copied!<p>I have the following XML result simplexml_load_string()...</p> <pre><code>SimpleXMLElement Object ( [Email] =&gt; xxxx@xxx.com [Acount] =&gt; 123123123 [Pin] =&gt; SimpleXMLElement Object ( ) [StartDate] =&gt; 20131204 [EndDate] =&gt; 20131204 [XML] =&gt; 1 [State] =&gt; 1 [Pays] =&gt; SimpleXMLElement Object ( ) [Collections] =&gt; SimpleXMLElement Object ( [Collection] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [Trx_id] =&gt; 6200106301 ) [Trx_Date] =&gt; 2013-12-04 07:44:04 [Trx_Payment] =&gt; 243.00 [Trx_MontoNeto] =&gt; 229.45 [Trx_Number] =&gt; 42183710 [Trx_PaymentMean] =&gt; Pago ) [1] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [Trx_id] =&gt; 6200081097 ) [Trx_Date] =&gt; 2013-12-04 07:43:58 [Trx_Payment] =&gt; 160.00 [Trx_MontoNeto] =&gt; 150.47 [Trx_Number] =&gt; 42183698 [Trx_PaymentMean] =&gt; Pago ) [2] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [Trx_id] =&gt; 6200173497 ) [Trx_Date] =&gt; 2013-12-04 07:43:25 [Trx_Payment] =&gt; 78.00 [Trx_MontoNeto] =&gt; 72.42 [Trx_Number] =&gt; 42183631 [Trx_PaymentMean] =&gt; Pago ) ) [Tickets] =&gt; SimpleXMLElement Object ( ) [Receptions] =&gt; SimpleXMLElement Object ( ) [Retreats] =&gt; SimpleXMLElement Object ( [Retreat] =&gt; SimpleXMLElement Object ( [Trx_Date] =&gt; 2013-12-04 14:04:36 [Trx_Payment] =&gt; 0,000.17 [Trx_MontoNeto] =&gt; 0,000.80 [Trx_Number] =&gt; 56757 [Trx_RetreatMethod] =&gt; bla bla bla [Trx_TypeCodIdentif] =&gt; C.U.I.L. [Trx_NumberCodIdentif] =&gt; 234234234 [Trx_Bank] =&gt; bank. [Trx_Address] =&gt; SimpleXMLElement Object ( ) [City] =&gt; SimpleXMLElement Object ( ) [Province] =&gt; SimpleXMLElement Object ( ) ) ) [Credits] =&gt; SimpleXMLElement Object ( ) [Debits] =&gt; SimpleXMLElement Object ( ) ) </code></pre> <p>I'm trying to recorver in a foreach clause all element like Trx_Id, Trx_date, etc...</p> <p>can anyone post code to do that?</p> <p>I've tried using</p> <pre><code>foreach ($xml-&gt;object as $dato) { print_r('data ' . $dato-&gt;field[2]); } </code></pre> <p>but nothing ...!</p> <p><em><strong>UPDATE:!!!!</em></strong></p> <p>using the following approach </p> <pre><code>foreach($xml-&gt;Collections-&gt;Collection as $result){ print_r('id ' . $result['Trx_id']. '&lt;br&gt;'); print_r('date ' . $result['Trx_Date']. '&lt;br&gt;'); print_r('Trx_Payment ' . $result['Trx_Payment']. '&lt;br&gt;'); print_r('Trx_Number ' . $result['Trx_Number']. '&lt;br&gt;'); print_r('Trx_PaymentMean ' . $result['Trx_PaymentMean']. '&lt;br&gt;'); print_r('......&lt;br&gt;'); } </code></pre> <p>I can olny get Trx_id</p> <p>as you can see</p> <pre><code>id 6200106301 date Trx_Payment Trx_Number Trx_PaymentMean </code></pre> <p>please take in care the structure</p> <pre><code>[Collections] =&gt; SimpleXMLElement Object ( [Collection] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [Trx_id] =&gt; 6200106301 ) [Trx_Date] =&gt; 2013-12-04 07:44:04 [Trx_Payment] =&gt; 243.00 [Trx_MontoNeto] =&gt; 229.45 [Trx_Number] =&gt; 42183710 [Trx_PaymentMean] =&gt; Pago ) </code></pre> <p>using vardump !!...</p> <pre><code>object(SimpleXMLElement)[1] public 'Email' =&gt; string 'xxxx@xxxx.com' (length=24) public 'Acount' =&gt; string 'xxxxx' (length=7) public 'Pin' =&gt; object(SimpleXMLElement)[2] public 'StartDate' =&gt; string '20131204' (length=8) public 'EndDate' =&gt; string '20131204' (length=8) public 'XML' =&gt; string '1' (length=1) public 'State' =&gt; string '1' (length=1) public 'Pays' =&gt; object(SimpleXMLElement)[3] public 'Collections' =&gt; object(SimpleXMLElement)[4] public 'Collection' =&gt; array (size=13) 0 =&gt; object(SimpleXMLElement)[10] ... 1 =&gt; object(SimpleXMLElement)[11] ... 2 =&gt; </code></pre> <p>UPDATE 2:</p> <p>Here is Pure XML called directly using web Browser</p> <pre><code>This XML file does not appear to have any style information associated with it. The document tree is shown below. &lt;Report&gt; &lt;Email&gt;xxxxx@dddddd.com&lt;/Email&gt; &lt;Acount&gt;234234234&lt;/Acount&gt; &lt;Pin/&gt; &lt;StartDate&gt;20131204&lt;/StartDate&gt; &lt;EndDate&gt;20131204&lt;/EndDate&gt; &lt;XML&gt;1&lt;/XML&gt; &lt;State&gt;1&lt;/State&gt; &lt;Pays/&gt; &lt;Collections&gt; &lt;Collection Trx_id="123123132"&gt; &lt;Trx_Date&gt;2013-12-04 07:44:04&lt;/Trx_Date&gt; &lt;Trx_Payment&gt;444.00&lt;/Trx_Payment&gt; &lt;Trx_MontoNeto&gt;444.45&lt;/Trx_MontoNeto&gt; &lt;Trx_Number&gt;333333&lt;/Trx_Number&gt; &lt;Trx_PaymentMean&gt;blabla&lt;/Trx_PaymentMean&gt; &lt;/Collection&gt; &lt;Collection Trx_id="34534345"&gt; &lt;Trx_Date&gt;2013-12-04 07:43:58&lt;/Trx_Date&gt; &lt;Trx_Payment&gt;160.00&lt;/Trx_Payment&gt; &lt;Trx_MontoNeto&gt;150.47&lt;/Trx_MontoNeto&gt; &lt;Trx_Number&gt;666666&lt;/Trx_Number&gt; &lt;Trx_PaymentMean&gt;blabla2&lt;/Trx_PaymentMean&gt; &lt;/Collection&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload