Jump to content

How to read a XML in PHP


gaggid

Recommended Posts

Hi everyone,

 

I need some help here. I don't know PHP coding and how to write custom php code for reading a XML in PHP. I have a application which updates the server status in real time and send out the data in XML format. I want to create a PHP page so that can show the data in XML to frontend user...

 

I am pasting the XML code that need to be converted in PHP. Any kind of help will be appreciated. If anybody can give me the code and displaying the data in table format that will be awesome....

 

 

<?xml version="1.0" encoding="UTF-8"?>
-<simplehelp_metrics builddate="20120419-123521" version="3.12">
-<technician_metrics> 
<metric value="2" name="Technicians Logged In" id="tech_logged_in"/> 
<metric value="0" name="Technicians In Session" id="tech_in_session"/> 
<metric value="0" name="Technicians In Remote Session" id="tech_in_remote_session"/> 
</technician_metrics> 
-<customer_metrics> 
<metric value="0" name="Customers Logged In" id="cust_logged_in"/> 
<metric value="0" name="Customers In Session" id="cust_in_session"/> 
<metric value="0" name="Customers Waiting" id="cust_waiting"/> 
</customer_metrics>
-<server_metrics> 
<metric value="1" name="Server Maximum Sessions" id="server_max_sessions"/> 
<metric value="23" name="Server Total Number of Sessions" id="server_total_sessions"/> 
<metric value="23" name="Server Total Number of Support Sessions" id="server_total_support_sessions"/> 
<metric value="0" name="Server Total Number of Access Sessions" id="server_total_access_sessions"/> 
<metric value="21217" name="Average Queue Time" id="server_average_queue_time"/>
<metric value="17052" name="Last Queue Time" id="server_last_queue_time"/> 
<metric value="1830883" name="Average Session Duration" id="server_average_session_time"/> 
<metric value="5932145" name="Last Session Duration" id="server_last_session_time"/> 
</server_metrics> 
-<technicians> 
<technician name="tlc10271" login="tlc10271"/> 
<technician name="tlc10072" login="tlc10072"/> 
</technicians> 
</simplehelp_metrics>

Link to comment
Share on other sites

use simpleXML

<?php
  $xml = simplexml_load_file('metrics.xml');

  echo "<table cellpadding=5>\n";
  
  foreach($xml->xpath('//metric') as $m) {
    echo "<tr><td>{$m['name']}</td><td>{$m['value']}</td></tr>\n";
  }

  echo "</table>\n";
?>
[/code

 

 

Thanks it worked... Only thing pending is making it look beautiful. Can you suggest me how i can apply some css to this php....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.