Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - transform value from XML field to HTML field with elements which is repeating?
    primarykey
    data
    text
    <p>I have xml field <code>$xmlstring</code> with value;</p> <pre><code>'&lt;result&gt; &lt;customerAccount xmlns="http://www.ibm.com&gt; &lt;AccountStatus xmlns=""&gt;Due&lt;/AccountStatus&gt; &lt;ComponentCustomerAccount xmlns=""&gt; &lt;Name&gt;ADSL&lt;/Name&gt; &lt;CharacteristicValue&gt; &lt;Characteristic&gt; &lt;Name&gt;Balance&lt;/Name&gt; &lt;/Characteristic&gt; &lt;Value&gt;0.0&lt;/Value&gt; &lt;/CharacteristicValue&gt; &lt;CharacteristicValue&gt; &lt;Characteristic&gt; &lt;Name&gt;Date&lt;/Name&gt; &lt;/Characteristic&gt; &lt;Value&gt;21.10.1990&lt;/Value&gt; &lt;/CharacteristicValue&gt; &lt;AccountStatus&gt;Active&lt;/AccountStatus&gt; &lt;/ComponentCustomerAccount&gt; &lt;ComponentCustomerAccount xmlns=""&gt; &lt;Name&gt;IPTV&lt;/Name&gt; &lt;CharacteristicValue&gt; &lt;Characteristic&gt; &lt;Name&gt;Balance&lt;/Name&gt; &lt;/Characteristic&gt; &lt;Value&gt;100&lt;/Value&gt; &lt;/CharacteristicValue&gt; &lt;CharacteristicValue&gt; &lt;Characteristic&gt; &lt;Name&gt;Date&lt;/Name&gt; &lt;/Characteristic&gt; &lt;Value&gt;21.10.1990&lt;/Value&gt; &lt;/CharacteristicValue&gt; &lt;AccountStatus&gt;Active&lt;/AccountStatus&gt; &lt;/ComponentCustomerAccount&gt; &lt;/customerAccount&gt; &lt;/result&gt;'; </code></pre> <p>I want to display in HTML field within table:</p> <pre><code>NAME STATUS VALUE ADSL ACTIVE 0.0 IPTV ACTIVE 100 </code></pre> <p>As you can see I have some elements which are repeating. ComponentCustomerAccount is repeating and I can have multiple elements. I do not need first AccountStatus element but I need AccountStatus element within ComponentCustomerAccount. Also I need first element Name within ComponentCustomerAccount element.</p> <pre><code> $xml = new SimpleXMLElement($xmlString); $html = "&lt;table&gt;"; $html .= "&lt;tr&gt;&lt;th&gt;Account Name&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;th&gt;Amount&lt;/th&gt;&lt;/tr&gt;"; foreach($xml-&gt;customerAccount as $cust) { $html .= "&lt;tr&gt;&lt;th&gt;" . $cust-&gt;Name . "&lt;/th&gt;&lt;th&gt;" . $cust-&gt;AccountStatus. "&lt;/th&gt;&lt;th&gt;" . $cust-&gt;Value . "&lt;/th&gt;&lt;/tr&gt;"; } $html .= "&lt;/table&gt;"; </code></pre> <p>But I am getting blank output. What do I have to change? Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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