I have a program that fetches TV series schedule data from an XML file and displays it on a webpage. However, when running the program, I encounter the following error message multiple times: “No Icon Found” for various TV series such as “Amour, gloire et beauté”, “Les Feux de l’amour”, “Plus belle la vie, encore plus belle”, etc.
The program parses the XML file, extracting information such as start and stop times, titles, descriptions, channels, and icon sources for each TV series. It then constructs a table to display this information on the webpage. However, it seems that some TV series entries in the XML file do not have associated icon sources, leading to the error message.
I need assistance in understanding why these errors occur and how to handle them effectively within the program.
Here is my HTML code :
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Programme TV - Séries</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 8px;
}
img {
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<div id="programmeContainer"></div>
<script>
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'series.xml',
dataType: 'xml',
success: function(xml) {
console.log("XML chargé avec succès"); // Debug
var programmes = {};
$(xml).find('programme').each(function() {
var start = $(this).find('start').text(); // Accès au contenu de l'élément <start>
var stop = $(this).find('stop').text(); // Accès au contenu de l'élément <stop>
if (start && stop) { // Vérifier que start et stop sont bien définis
var date = new Date(parseInt(start.substring(0, 4)), parseInt(start.substring(4, 6))-1, parseInt(start.substring(6, 8)));
var dateString = date.toISOString().split('T')[0]; // Format YYYY-MM-DD
var title = $(this).find('title').text();
var desc = $(this).find('desc').text();
var channel = $(this).find('channel').text();
var iconSrc = $(this).find('channel > icon').text();
if (!iconSrc) {
console.log('Aucune icône trouvée pour:', $(this).find('title').text());
}
var programmeData = {
time: start.substring(8, 10) + ':' + start.substring(10, 12),
title: title,
desc: desc,
channel: channel,
iconSrc: iconSrc
};
if (!programmes[dateString]) {
programmes[dateString] = [];
}
programmes[dateString].push(programmeData);
} else {
console.log('Données "start" ou "stop" manquantes pour un élément <programme>');
}
});
console.log(programmes); // Final data structure debug
for (var day in programmes) {
var table = $('<table><tr><th>Heure</th><th>Titre</th><th>Chaîne</th><th>Icône</th><th>Description</th></tr></table>');
programmes[day].forEach(function(prog) {
table.append('<tr><td>' + prog.time + '</td><td>' + prog.title + '</td><td>' + prog.channel + '</td><td><img src="'+prog.iconSrc +'" alt="Icon"></td><td>' + prog.desc + '</td></tr>');
});
$('#programmeContainer').append(table);
}
},
error: function() {
console.error('Erreur de chargement du fichier XML'); // Error handling
alert('Erreur de chargement du fichier XML');
}
});
});
</script>
</body>
</html>
Here is a fragement of my XML file :
<channel>
<id>PlanetePlus.fr</id>
<display-name>Planete+</display-name>
<icon>https://focus.telerama.fr/500x500/0000/00/01/clear-147.png</icon>
</channel>
<programme>
<title>Amour, gloire et beauté</title>
<desc>Hope a failli laisser échapper ses vrais sentiments pour Thomas, mais il a mal interprété ses efforts et lui dit qu'il la respecte, elle et son mariage.</desc>
<category>Série</category>
<start>20240506103000 +0200</start>
<stop>20240506110000 +0200</stop>
<channel>TF1.fr</channel>
</programme>
I need to fetch the icon image link to display it