I don't understand why the xsl file is not being applied when the xml is echoed from php. I checked the output in postman and the data is also being recorded in the database but it is still not formatted in the browser. Am i missing something in php?
PHP File (addSong_xml.php)
<?php
$title = "";
$artist = "";
$year = "";
$songs = $_POST['txt_xml_songs'];
$xml_Doc = new DOMDocument();
$xml_Doc->loadXML($songs);
if(!$xml_Doc->schemaValidate('songs.xsd'))
echo "XML not valid.";
else
{
include('db_connect.php');
header('Content_Type: text/xml');
$xml_songs = simplexml_import_dom($xml_Doc);
foreach($xml_songs->Song as $song)
{
$title = $song->Title;
$artist = $song->Artist;
$year = $song->Year;
if($title != "" && $title != null)
{
$sql = "SELECT * FROM Songs WHERE Title='$title'";
$result = mysqli_query($mysqli, $sql);
if(mysqli_num_rows($result) < 1)
{
$sql ="INSERT INTO Songs (Title, Artist, Year) VALUES ('$title', '$artist', '$year')";
if(!mysqli_query($mysqli, $sql))
{
die('Error: ' . mysqli_error($mysqli));
}
}
}
}
$xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$xml_output = $xml_output."<?xml-stylesheet type=\"text/xsl\" href=\"songs.xsl\"?>";
$xml_output = $xml_output.$songs;
echo $xml_output;
mysqli_close($mysqli);
}
?>
Aucun commentaire:
Enregistrer un commentaire