I have a file, “books.xml” with this:
<?xml version = "1.0" encoding = "utf-8"?>
<tutorialspoint>
<course category = "JAVA">
<title lang = "en">Java</title>
<tutor>Gopal</tutor>
<duration></duration>
<price>$30</price>
</course>
<course category = "HADOOP">
<title lang = "en">Hadoop</title>.
<tutor>Satish</tutor>
<duration>3>/duration>
<price>$50</price>
</course>
<course category = "HTML">
<title lang = "en">html</title>
<tutor>raju</tutor>
<duration>5</duration>
<price>$50</price>
</course>
<course category = "WEB">
<title lang = "en">Web Technologies</title>
<tutor>Javed</tutor>
<duration>10</duration>
<price>$60</price>
</course>
</tutorialspoint>
I have a main file with this:
<?php
$xml = simplexml_load_file("books.xml") or die("Error: Cannot create object");
foreach($xml->children() as $books) {
echo $books->title . "<br> ";
echo $books->tutor . "<br> ";
echo $books->duration . "<br> ";
echo $books->price . "<hr>";
}
?>
-----------------------------
It outputs:
children() as $books) { echo $books->title . “
”; echo $books->tutor . “
”; echo $books->duration . “
”; echo $books->price . “
”; } ?>
can view here: https://iglooo.000webhostapp.com/xml/php.html
What am I doing wrong?