0
<?php
$bookxml =simplexml_load_file("book.xml");

print_r($bookxml);  
echo"Display this";

?>

xml file

<xml version="1.0" encoding="UTF-8">
<book>
    <bookcode>COMPUTER</bookcode>
    <bookname>LEARN PHP</bookname>
    <bookauthor>Balguruswamy</bookauthor>
    <publisher>Arihant</publisher>
    <price>645.50</price>
</book>
<book>
    <bookcode>Maths</bookcode>
    <bookname>Solve Trig</bookname>
    <bookauthor>A.B.C</bookauthor>
    <publisher>TM</publisher>
    <price>150.42</price>
</book>
<book>
    <bookcode>English</bookcode>
    <bookname>Prose</bookname>
    <bookauthor>D .E.EF</bookauthor>
    <publisher>Vision</publisher>
    <price>64.65</price>
</book>
<book>
    <bookcode>COMPUTER</bookcode>
    <bookname>LEARN JAVA</bookname>
    <bookauthor>Balguruswamy</bookauthor>
    <publisher>Penguin</publisher>
    <price>424.9</price>
</book>


I can see the xml file when I run the php script in terminal using php filename.php but cannot see it when I try to do from apache localhost on my browser. What should I do ?

Edit:

When I open error log for apache2 I saw this.

[Sun Jan 28 10:35:16.301835 2018] [mpm_event:notice] [pid 9407:tid 140581351434112] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 10:35:16.301914 2018] [core:notice] [pid 9407:tid 140581351434112] AH00094: Command line: '/usr/sbin/apache2' [Sun Jan 28 10:47:21.326245 2018] [mpm_event:notice] [pid 9407:tid 140581351434112] AH00491: caught SIGTERM, shutting down [Sun Jan 28 10:47:22.379645 2018] [mpm_event:notice] [pid 10070:tid 139652613879680] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 10:47:22.379716 2018] [core:notice] [pid 10070:tid 139652613879680] AH00094: Command line: '/usr/sbin/apache2' [Sun Jan 28 10:47:25.835120 2018] [mpm_event:notice] [pid 10070:tid 139652613879680] AH00491: caught SIGTERM, shutting down [Sun Jan 28 10:47:26.887422 2018] [mpm_event:notice] [pid 10176:tid 140391800403840] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 10:47:26.887537 2018] [core:notice] [pid 10176:tid 140391800403840] AH00094: Command line: '/usr/sbin/apache2' [Sun Jan 28 10:47:30.516640 2018] [authz_core:error] [pid 10179:tid 140391718758144] [client 127.0.0.1:49064] AH01630: client denied by server configuration: /home/pushkarrao/Work/apachetrue/ [Sun Jan 28 10:47:30.631338 2018] [authz_core:error] [pid 10179:tid 140391701972736] [client 127.0.0.1:49064] AH01630: client denied by server configuration: /home/pushkarrao/Work/apachetrue/favicon.ico [Sun Jan 28 10:47:30.794247 2018] [authz_core:error] [pid 10179:tid 140391710365440] [client 127.0.0.1:49064] AH01630: client denied by server configuration: /home/pushkarrao/Work/apachetrue/favicon.ico [Sun Jan 28 10:53:03.602646 2018] [mpm_event:notice] [pid 10176:tid 140391800403840] AH00491: caught SIGTERM, shutting down [Sun Jan 28 10:53:04.686297 2018] [mpm_event:notice] [pid 10534:tid 139701054691200] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 10:53:04.686390 2018] [core:notice] [pid 10534:tid 139701054691200] AH00094: Command line: '/usr/sbin/apache2' [Sun Jan 28 19:41:28.732489 2018] [mpm_event:notice] [pid 10534:tid 139701054691200] AH00491: caught SIGTERM, shutting down [Sun Jan 28 19:41:29.794682 2018] [mpm_event:notice] [pid 13440:tid 139628059764608] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Sun Jan 28 19:41:29.794753 2018] [core:notice] [pid 13440:tid 139628059764608] AH00094: Command line: '/usr/sbin/apache2'

12
  • If you don't see the "Display this" then probably your script crashes. First thing to do is to check your http servers error log file, that is where php logs issues to. What does it say? Most likely a "File not found" due to a path issue... Commented Jan 29, 2018 at 4:02
  • Please add additional information to the question itself, not in comments. There is an edit link below your question, use it. Commented Jan 29, 2018 at 4:09
  • Well, you can tell yourself when looking through that log, various restarts, but nothing relevant. Commented Jan 29, 2018 at 4:11
  • Another guess: maybe all works fine, except that you output the actual xml which cannot be displayed by an html display program (a browser)? Check the page source you loaded into the browser. Commented Jan 29, 2018 at 4:11
  • Yeah. So what might be the problem ? Commented Jan 29, 2018 at 4:12

1 Answer 1

0

I think your xml structure is not proper :

It should be like this :

<?xml version="1.0" encoding="utf-8"?>
<books>
 <book>
    <bookcode>COMPUTER</bookcode>
    <bookname>LEARN PHP</bookname>
    <bookauthor>Balguruswamy</bookauthor>
    <publisher>Arihant</publisher>
    <price>645.50</price>
</book>
<book>
    <bookcode>Maths</bookcode>
    <bookname>Solve Trig</bookname>
    <bookauthor>A.B.C</bookauthor>
    <publisher>TM</publisher>
    <price>150.42</price>
</book>
<book>
    <bookcode>English</bookcode>
    <bookname>Prose</bookname>
    <bookauthor>D .E.EF</bookauthor>
    <publisher>Vision</publisher>
    <price>64.65</price>
</book>
<book>
    <bookcode>COMPUTER</bookcode>
    <bookname>LEARN JAVA</bookname>
    <bookauthor>Balguruswamy</bookauthor>
    <publisher>Penguin</publisher>
    <price>424.9</price>
</book>
</books>

your PHP code to get the xml elements :

<?php
     $bookxml =simplexml_load_file("book.xml");
     echo '<pre>';
     print_r($bookxml);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.