How to display JSON>XML output in tables using PHP ?

Hi,

I have the following XML after converting from JSON to XML :

<json>
  <metadata>
    <result>1</result>
    <reason>Zone Serialized</reason>
    <version>1</version>
    <command>dumpzone</command>
  </metadata>
  <data>
    <zone>
      <record>
        <ttl>86400</ttl>
        <Line>1</Line>
        <type>:RAW</type>
        <raw>; cPanel first:11.36.1.5 (update_time):1535217363 Cpanel::ZoneFile::VERSION:1.3 hostname:main.internet-webhosting.com latest:74.0.6</raw>
      </record>
      <record>
        <type>:RAW</type>
        <Line>2</Line>
        <ttl>86400</ttl>
        <raw>; Zone file for 170.26.8.103.in-addr.arpa</raw>
      </record>
      <record>
        <ttl>14400</ttl>
        <Line>3</Line>
        <type>$TTL</type>
      </record>
      <record>
        <name>170.26.8.103.in-addr.arpa.</name>
        <serial>2013042202</serial>
        <Line>4</Line>
        <ttl>86400</ttl>
        <expire>3600000</expire>
        <type>SOA</type>
        <retry>7200</retry>
        <class>IN</class>
        <refresh>86400</refresh>
        <mname>cns1.internet-webhosting.com</mname>
        <minimum>86400</minimum>
        <rname>report.internet-webhosting.com</rname>
        <Lines>6</Lines>
      </record>
      <record>
        <raw />
        <type>:RAW</type>
        <Line>10</Line>
        <ttl>86400</ttl>
      </record>
      <record>
        <nsdname>cns1.internet-webhosting.com</nsdname>
        <name>170.26.8.103.in-addr.arpa.</name>
        <type>NS</type>
        <class>IN</class>
        <Line>11</Line>
        <ttl>86400</ttl>
      </record>
      <record>
        <Line>12</Line>
        <ttl>86400</ttl>
        <type>NS</type>
        <class>IN</class>
        <name>170.26.8.103.in-addr.arpa.</name>
        <nsdname>cns2.internet-webhosting.com</nsdname>
      </record>
      <record>
        <raw />
        <ttl>86400</ttl>
        <Line>13</Line>
        <type>:RAW</type>
      </record>
      <record>
        <ttl>86400</ttl>
        <Line>14</Line>
        <type>:RAW</type>
        <raw />
      </record>
      <record>
        <name>170.26.8.103.in-addr.arpa.</name>
        <class>IN</class>
        <type>A</type>
        <address>103.8.26.170</address>
        <Line>15</Line>
        <ttl>14400</ttl>
      </record>
      <record>
        <raw />
        <type>:RAW</type>
        <ttl>86400</ttl>
        <Line>16</Line>
      </record>
      <record>
        <address>127.0.0.1</address>
        <class>IN</class>
        <type>A</type>
        <Line>17</Line>
        <ttl>14400</ttl>
        <name>localhost.170.26.8.103.in-addr.arpa.</name>
      </record>
      <record>
        <Line>18</Line>
        <ttl>86400</ttl>
        <type>:RAW</type>
        <raw />
      </record>
      <record>
        <type>MX</type>
        <class>IN</class>
        <preference>0</preference>
        <Line>19</Line>
        <ttl>14400</ttl>
        <exchange>170.26.8.103.in-addr.arpa</exchange>
        <name>170.26.8.103.in-addr.arpa.</name>
      </record>
      <record>
        <ptrdname>khansforge.com</ptrdname>
        <name>170.26.8.103.in-addr.arpa.</name>
        <class>IN</class>
        <type>PTR</type>
        <ttl>14400</ttl>
        <Line>20</Line>
      </record>
    </zone>
  </data>
</json>

Open in new window




May i know how to put the above result between "<record>  </record>" in tables ?

If possible, i just would like to display the result that only contain "PTR" in <record></record>

Eg:

 <record>
        <ptrdname>khansforge.com</ptrdname>
        <name>170.26.8.103.in-addr.arpa.</name>
        <class>IN</class>
        <type>PTR</type>
        <ttl>14400</ttl>
        <Line>20</Line>
      </record>

Appreciates anybody assistant on this request.
LVL 2
Shamsul KamalJunior TechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
Why do you convert json to xml? Php can easily manage json output using json_decode()...
0
Steve BinkCommented:
I agree with Marco Gasi - manipulating JSON is going to be simpler than dealing with XML.  

To do this with the JSON, it is pretty simple:
$items = json_decode($the_json);

// I'm assuming the decode is in arrays.  
// If it is returning objects, syntax will be slightly different.

// iterate through the zones
foreach ($items['data'] as $zone_key=>$zone) {
  // maybe do stuff here..  new table?  div?  whatever

  // iterate through zone's records
  foreach ($zone as $rec_key=>$record) {
    // you can filter here by checking the type
    if ($record['type'] == 'PTR') { 
      // do all the cool things
    }
  }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shamsul KamalJunior TechAuthor Commented:
Thanks to all of you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.