I have found a source of and aledged xml file (although it is named as solarxml.php, when I download it the data that I want is there, i.e. solarflux, aindex, kindex and sunspots, but I have no idea how to determine how to extract the 4 data fields I want, also don't want to download it each time as I want to use those 4 items on my webpage (unless the webpage is reloaded), this when refreshed or reloaded would force a reload of the xml data and thus keeping the information fresh.

I have looked at many tutorials and now seem to be chasing myself in circles. The xml file can be found at: http://www.hamqsl.com/solarxml.php (I have confirmed it is a legit xml file) will of course acknowledge the source of the info, although it is all in the public domain. So a snippet of code to get me started would be great, I am sure that this will be like falling off a log to some of you but to me, who has spent 4 days scratching my head seem like a big problem.

So any test coding I can manipulate would be really helpful, especially showing how to get the xml from an external server.

I can't use the usual formats such as php etc as the host I use does not have them enabled.

Thanks in anticipation

Dani AI

Generated

Quick summary for (and following on 's comment): there are two practical paths.

  1. Pure client-side: let the browser fetch the XML and parse it with DOMParser, then read the tags you need (solarflux, aindex, kindex, sunspots). This only works if the remote server allows cross-origin requests (the server must send the appropriate CORS header). If it does, a single fetch on page load is enough — the page will only re-download when you reload. (devdoc.net)

Example client-side pattern (replace the URL placeholder with your XML endpoint):

const XML_URL = 'PUT_XML_URL_HERE';

async function loadSolar() {
  const res = await fetch(XML_URL, { mode: 'cors' });
  if (!res.ok) throw new Error('Network response not ok: ' + res.status);
  const text = await res.text();
  const doc = new DOMParser().parseFromString(text, 'application/xml');
  if (doc.querySelector('parsererror')) throw new Error('Bad XML');
  const get = tag => (doc.querySelector(tag) || { textContent: '' }).textContent.trim();
  const solarflux = get('solarflux');
  const aindex = get('aindex');
  const kindex = get('kindex');
  const sunspots = get('sunspots');
  // update DOM with these values
}
document.addEventListener('DOMContentLoaded', loadSolar);

DOMParser handles XML parsing in the browser; check for a <parsererror> node if parsing fails. If the fetch fails with a CORS error, the browser console will show the usual "blocked by CORS policy" message. (developer.mozilla.org)

  1. If CORS is not allowed by the data host (or the host uses bot-protection that blocks direct browser requests), use a tiny proxy that fetches the XML server-side and returns it (or JSON) with an Access-Control-Allow-Origin header. A Cloudflare Worker is a quick free option: fetch the remote XML inside the Worker, return it to the browser and add the CORS header. This avoids needing PHP on your host and lets your page fetch the Worker URL instead. Example and docs here. (developers.cloudflare.com)

If you prefer a scheduled server-side pull that saves JSON or a small static file on a server (so your site just reads the local file), there are small Python examples showing how to fetch and parse the same XML server-side (requests + lxml). That approach also avoids CORS entirely. (gist.github.com)

Troubleshooting checklist: inspect the network request and response headers (look for Access-Control-Allow-Origin), check console for parser or CORS errors, and test parsing with a saved copy of the XML (to verify selectors). If you hit a specific error, post the exact console/network error and the fetch/response headers and someone can point to the exact fix.

though you might want to open up a new question if you hit any issues

Did you hit any issues with the libraries then? If so you might want to mention them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.