gaggid Posted May 16, 2012 Share Posted May 16, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/262622-how-to-read-a-xml-in-php/ Share on other sites More sharing options...
ScotDiddle Posted May 16, 2012 Share Posted May 16, 2012 gaggid, Take a look at this class... It writes, then reads (parses) the content of an XML File. http://www.phpclasses.org/browse/file/19181.html Scot L. Diddle, Richmond VA Quote Link to comment https://forums.phpfreaks.com/topic/262622-how-to-read-a-xml-in-php/#findComment-1345988 Share on other sites More sharing options...
gaggid Posted May 16, 2012 Author Share Posted May 16, 2012 Thanks for your reply. However i don't understand how to use yoursay with the kind of XML i want to show in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/262622-how-to-read-a-xml-in-php/#findComment-1345992 Share on other sites More sharing options...
Barand Posted May 16, 2012 Share Posted May 16, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/262622-how-to-read-a-xml-in-php/#findComment-1346013 Share on other sites More sharing options...
gaggid Posted May 16, 2012 Author Share Posted May 16, 2012 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.... Quote Link to comment https://forums.phpfreaks.com/topic/262622-how-to-read-a-xml-in-php/#findComment-1346016 Share on other sites More sharing options...
Barand Posted May 16, 2012 Share Posted May 16, 2012 you could add "class='xxxx' " to the TD tags Quote Link to comment https://forums.phpfreaks.com/topic/262622-how-to-read-a-xml-in-php/#findComment-1346017 Share on other sites More sharing options...
gaggid Posted May 16, 2012 Author Share Posted May 16, 2012 thanks i got it... I wrapped the page in joomla and applied joomla template css to it. thanks....you guys are great. Quote Link to comment https://forums.phpfreaks.com/topic/262622-how-to-read-a-xml-in-php/#findComment-1346056 Share on other sites More sharing options...
ignace Posted May 16, 2012 Share Posted May 16, 2012 Be sure to donate some of that money you just made with some help from us Quote Link to comment https://forums.phpfreaks.com/topic/262622-how-to-read-a-xml-in-php/#findComment-1346061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.