0

How can i read the below xml in a php file, so that the output should be a table in php.

<?xml version="1.0" ?>
<Response command="GenerateReport" module="DB" status = "success">
<Applied_Filters>
<Groups> Customer_Name</Groups>
<Period>01/24/2015</Period>
<Time_Zone>India Standard Time</Time_Zone>
</Applied_Filters>
<Report name="All Nodes CPU Usage">
<Row>
<Column id="Node" name="Node">azim</Column>
<Column id="ResourceName" name="ResourceName">0</Column>
<Column id="MaxUsage(%)(graph)" name="MaxUsage">13.00</Column>
<Column id="AvgUsage(%)(graph)" name="AvgUsage">2.19</Column>
</Row>
<Row>
<Column id="Node" name="Node">azim</Column>
<Column id="ResourceName" name="ResourceName">FG100</Column>
<Column id="MaxUsage(%)(graph)" name="MaxUsage">3.00</Column>
<Column id="AvgUsage(%)(graph)" name="AvgUsage">2.18</Column>
</Row>
</Report>
</Response>

i have tried the below php code, unfortunately i am getting an error"Fatal error: Call to a member function item() on a non-object"

<?php
// This is a simple example on how to draw a chart using FusionCharts and PHP.
// We have included includes/fusioncharts.php, which contains functions
// to help us easily embed the charts.
    include('fusioncharts.php');

 $doc = new DOMDocument(); 
$doc->load('response.xml'); 

$employees = $doc->getElementsByTagName("Row");


foreach( $employees as $Row ) 
{   

  $names = $Row->getAttribute("Node"); 
  $Node = $names->item(0)->nodeValue; 

  $ages= $Row->getAttribute("MaxUsage"); 
  $MaxUsage= $ages->item(0)->nodeValue; 

  $salaries = $Row->getAttribute("AvgUsage"); 
  $AvgUsage = $salaries->item(0)->nodeValue; 

  echo "<b>$Node - $MaxUsage - $AvgUsage\n</b><br>"; 
  }  
?>
  • Please state what you want the result to be like. For now, the answer to your question is: with a xml parser – baao Jan 24 '15 at 19:34
  • the result should be a table in php. Node ResourceName MaxUsage(%)(graph) AvgUsage(%)(graph) azim_182.18.153.103 0 13 2.19 azim_premji_fw FG100C3G11609780 3 2.18 – Pradeep Vempati Jan 24 '15 at 19:36
  • and again, please state which fields you want to read. Your question like it is right now is subject to be closed as unclear what you are asking. You should also include your code where we can see what you have tried so far – baao Jan 24 '15 at 19:37
  • i have posted what i have tried above – Pradeep Vempati Jan 24 '15 at 20:06

0 Answers0