1

This is what I have created. It appears the script never gets to the Data:

!DOCTYPE html>
<html>
<head>
    <title>XML Feed </title>
    <script>
        // Fetch and parse the XML feed
        function fetchXMLFeed() {
            fetch('https://solidsports.com.au/scores/Venue_GPS/live/Scores.xml')
                .then(response => response.text())
                .then(data => {
                    const parser = new DOMParser();
                    const xmlDoc = parser.parseFromString(data, 'text/xml');
                    const items = xmlDoc.getElementsByTagName('item');
                    
                    // Iterate through each item and display the description for the needed titles 
                    let descriptionContainer = document.getElementById('description-container');
                    for (let i = 0; i < items.length; i++) {
                      let title = items[i].getElementsByTagName('title')[0].textContent;
                      let descript = items[i].getElementsByTagName('description')[0].textContent;
                        
                      if (`your text`title === 'AwayPoints') {
                  descriptionContainer.textContent = descript;
                          break;
                        }
                    }
                })
                .catch(error => {
                    console.error('Error fetching XML feed:', error);
                });
        }
    </script>
</head>
<body onload="fetchXMLFeed()">
    <h2>Description for Item with Title "AwayPoints":</h2>
    <div id="description-container"></div>
</body>
</html>

the html code does not provide any output I have tried adding elements within the Data =>{} construct and displaying them in the html. It appears the script never gets to the data. I am sure there is something simple I am not doing, but being new to this I can't figure it out. Any help or comments would be greatfully received. Thanks

Rob Melloy
  • 11
  • 1
  • Please make sure that your script can fetch the XML (CORS!) and provide an example. – ThW Jul 07 '23 at 08:53
  • Thanks for that, There does not seem to be an error caught, and I know the xml feed is good as I can see it when I put the address in the search bar, But it does look like the script cant fetch. I don't understand the (CORS!) reference in your answer. – Rob Melloy Jul 07 '23 at 08:57
  • Make sure that the BROWSER can fetch the XML using JS - not just open it as a separate request. Use the developer tools of the bowser. CORS is a security mechanism limiting requests. You should get a warning/error message in the browser console. – ThW Jul 07 '23 at 09:35

0 Answers0