PHP - transform value from XML field to HTML field with elements which is repeating? -


i have xml field $xmlstring value;

'<result>   <customeraccount xmlns="http://www.ibm.com>     <accountstatus xmlns="">due</accountstatus>      <componentcustomeraccount xmlns="">       <name>adsl</name>       <characteristicvalue>         <characteristic>           <name>balance</name>         </characteristic>         <value>0.0</value>       </characteristicvalue>       <characteristicvalue>         <characteristic>           <name>date</name>         </characteristic>         <value>21.10.1990</value>       </characteristicvalue>       <accountstatus>active</accountstatus>     </componentcustomeraccount>      <componentcustomeraccount xmlns="">       <name>iptv</name>       <characteristicvalue>         <characteristic>           <name>balance</name>         </characteristic>         <value>100</value>       </characteristicvalue>       <characteristicvalue>         <characteristic>           <name>date</name>         </characteristic>         <value>21.10.1990</value>       </characteristicvalue>       <accountstatus>active</accountstatus>     </componentcustomeraccount>     </customeraccount> </result>'; 

i want display in html field within table:

name       status     value  adsl       active     0.0 iptv       active     100 

as can see have elements repeating. componentcustomeraccount repeating , can have multiple elements. not need first accountstatus element need accountstatus element within componentcustomeraccount. need first element name within componentcustomeraccount element.

    $xml = new simplexmlelement($xmlstring);      $html = "<table>";     $html .= "<tr><th>account name</th><th>status</th><th>amount</th></tr>";     foreach($xml->customeraccount $cust) {       $html .= "<tr><th>" . $cust->name .  "</th><th>" . $cust->accountstatus. "</th><th>" . $cust->value . "</th></tr>";       }      $html .= "</table>"; 

but getting blank output. have change? thank you

your xml missing close quote in <customeraccount xmlns="http://www.ibm.com>. once fix that, need iterate on componentcustomeraccount inside of loop:

foreach($xml->customeraccount $ca) {     foreach ($ca->componentcustomeraccount $cust) {         $html .= "<tr><th>" . $cust->name         . "</th><th>" . $cust->accountstatus. "</th><th>"         . $cust->characteristicvalue->value . "</th></tr>";     } } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -