Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP parsing XML data
    primarykey
    data
    text
    <p>I am parsing an xml file successfully in PHP, but having difficulty parsing a specific entry trying to output a table.</p> <p>My xml is as follow</p> <pre><code>&lt;OutputData Name="ExchangeRate" ContentTypeID=""&gt; &lt;DataTitle&gt;Exchange&lt;/DataTitle&gt; &lt;DataInfo&gt; &lt;TABLE CLASS="DataTable"&gt; &lt;TR&gt;&lt;TD&gt;1.00 GBP = 1.68 ALL&lt;/TD&gt;&lt;/TR&gt; &lt;TR&gt;&lt;TD&gt;1.00 USD = 1.58 ALL&lt;/TD&gt;&lt;/TR&gt; &lt;TR&gt;&lt;TD&gt;1.00 EUR = 1.35 ALL&lt;/TD&gt;&lt;/TR&gt; &lt;TR&gt;&lt;TD&gt;Currency conversion rates as of January 2012&lt;/TD&gt;&lt;/TR&gt; &lt;/TABLE&gt; &lt;/DataInfo&gt; &lt;/OutputData&gt; </code></pre> <p>if I try to output it this way <code>$info = $outputinfo-&gt;DataInfo;</code> I am getting an error.</p> <p>any help?</p> <p>My code is as follow</p> <pre><code>$xmlfile = $currenttitle.".xml"; $info = simplexml_load_file($xmlfile); $region = $country-&gt;Region[0]; $section = $region-&gt;Section; if($info){ foreach ($region-&gt;Section as $sectioninfo){ $title = $sectioninfo-&gt;SectionTitle; echo "&lt;b&gt;$title&lt;/b&gt;&lt;br /&gt;\n"; $output = $sectioninfo-&gt;OutputData; foreach ($sectioninfo-&gt;OutputData as $outputinfo){ $titleinfo = $outputinfo-&gt;DataTitle; $info = $outputinfo-&gt;DataInfo; } } </code></pre> <p>for the section above, I get the Title display, as Exchange, but the Table is not rendered.</p> <p>SOLUTION Thanks to h4b0 who put me in the right direction</p> <pre><code>$rowinfo = $outputinfo-&gt;DataInfo-&gt;TABLE-&gt;TR-&gt;TD; foreach ($outputinfo-&gt;DataInfo-&gt;TABLE-&gt;TR as $rowexchange){ echo $rowexchange-&gt;TD."&lt;br /&gt;"; } </code></pre>
    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.
 

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