How to get access XML file from Javascript (two ways and every thing bug )

— I try everything on internet and nothing work (Only vanilla CSS + XML + XSL) —

I am try to get access XML value from javaScript but it doesn’t work

First time I try to do it

function loadXMLDoc(filename)
if (window.ActiveXObject)
  xhttp = new ActiveXObject("Msxml2.XMLHTTP");
  xhttp = new XMLHttpRequest();
  }"GET", filename, false);
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11
return xhttp.responseXML;

function displayResult()
xml = loadXMLDoc("cdcatalog.xml");
xsl = loadXMLDoc("cdcatalog.xsl");
// code for IE
if (window.ActiveXObject || xhttp.responseType == "msxml-document")
  ex = xml.transformNode(xsl);
  document.getElementById("example").innerHTML = ex;
// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  xsltProcessor = new XSLTProcessor();
  resultDocument = xsltProcessor.transformToFragment(xml, document);

And have error on that –"GET", filename, false); line.
Another way I am try do from this video with Loading XML Data Using Fetch, and he tell me SCRIPT1002: Syntax error on first line for example fetch('./Albums.xml').then(() => 2)

I share some code I hope you can help me fix that issue, only try to get value on javascript.

ok my XML

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="sheet.xsl"?>
blah blah blah

My XSL file

<?xml version="1.0"  encoding ="UTF-8" ?>
<xsl:stylesheet version="1.0 "
    <xsl:template match="/xmlTag">

            <link rel="stylesheet" href="styles.css"/>
            <body id="id">
                 // some code

        <script src="./javaScript.js"></script> // link to my js file


Js file

fetch('./Albums.xml').then(() => 2)

I need to change js file or approach (The connection between files)?
How can I get xml values from Js ?

Thanks guys really appreciate

69 thoughts on “How to get access XML file from Javascript (two ways and every thing bug )”

  1. Its such as you read my mind! You seem to grasp a lot approximately this, such as you wrote the
    book in it or something. I believe that you just can do
    with some p.c. to force the message house a bit,
    but instead of that, this is excellent blog. A great read.
    I’ll certainly be back.

  2. Excellent post. I was checking constantly this weblog
    and I’m inspired! Extremely helpful information particularly the last section :
    ) I maintain such info a lot. I used to be seeking this certain information for a very lengthy time.
    Thanks and good luck.