0

I have an XML file on my server which is residing at a private location, so the file cannot be accessed via URL. I am trying to read the contents of the XML file using PHP and want to display it in an HTML page. I have tried several methods such as setting the header('Content-type: text/xml') but nothing seems to be working. The page is displayed as an empty text. I want to display the XML file similar to way it is displayed in the browser.

The XML that I have to display is something like this.

<simplexmlresult version="1.3" xmlns="http://sdk.prometric.com/schemas/SimpleXMLResults1_3">
<demographics>
    <demographic name="Activity" value="5"></demographic>
    <demographic name="AddUser" value="20130000"></demographic>
</demographics>
<exam resourcefilename="73392.cer" resourceversion="1.0" name="temp"></exam>
</simplexmlresult>

PHP code for reading file:-

<?php
header("Content-type: text/xml; charset=utf-8");
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$elig_id = $_GET['eid'];

if($elig_id) {
    $filename   = get_file_name_from_eligibility($elig_id);
    $file   = file_get_contents('./folder/temp/done/'.$filename);
    print $file;
}
?>
Shekhar Chikara
  • 3,786
  • 2
  • 29
  • 52
  • Show your PHP code for reading that XML file. – Jenson M John Jan 20 '14 at 13:00
  • Where's get_file_name_from_eligibility function defnition? – Jenson M John Jan 20 '14 at 13:09
  • I checked if the function is returning the value. I can see the complete XML if I do 'Inspect Element' in the browser. – Shekhar Chikara Jan 20 '14 at 13:13
  • get_file_name_from_eligibility function returns just filename or XML data itself? – Jenson M John Jan 20 '14 at 13:15
  • A blank page means that your script is throwing an error but you haven't configured PHP to display error messages. That's something you need to fix before you go further unless you want to waste your time guessing; it's impossible to code properly without the aid of error messages. Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). Other than that, you say you want to display XML inside HTML but your code doesn't have HTML at all—it even sends an XML content-type header. I suspect your description is wrong: you just to send the raw XML, don't you? – Álvaro González Jan 20 '14 at 13:18
  • @JensonMJohn It just returns the filename with an extension of '.xml' – Shekhar Chikara Jan 20 '14 at 13:22
  • @ShekharChikara like @ ÁlvaroGVicario mentioned your script might be having some errors. Please turn on error display & check. I've just checked myself a sample http://pastebin.com/Wx6uJLd5 this works well! – Jenson M John Jan 20 '14 at 13:24
  • @ÁlvaroG.Vicario I've already set error_reporting to All.. But there are not errors being displayed. Yes, its true that I only want to display the XML content in a tree-structure on the page. – Shekhar Chikara Jan 20 '14 at 13:24
  • @ShekharChikara Can I see the URL path for that XML? – Jenson M John Jan 20 '14 at 13:37
  • The tree-structure is generated by the browser and, in my experience, not all browsers have this feature natively. I suspect this has nothing to do with XML. Have you verified that your if() condition is true? Have you var_dump()'ed your variables to see what they contain? – Álvaro González Jan 21 '14 at 08:22

3 Answers3

0

Try with:

header( "content-type: application/xml; charset=ISO-8859-15" ); 
Jenson M John
  • 5,499
  • 5
  • 30
  • 46
0

call this

header("Content-type: text/xml; charset=utf-8"); 
Agha Umair Ahmed
  • 1,037
  • 7
  • 12
0

This is how I do it:

<?php 
header("Content-type: text/xml; charset=utf-8");  
readfile('sitemapindex.xml');
Andrew
  • 7,619
  • 13
  • 63
  • 117