XML : Uncaught TypeError: Cannot read property 'getElementsByTagName' of undefined [duplicate]

This question already has an answer here:

So, firstly the layout of the XML file quran-uthmani.xml is as follows:

 <quran>     <sura index="1" name="الفاتحة">         <aya index="1" text="بِسْمِ ٱللَّهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ" />         <aya index="2" text="ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ" />         <aya index="3" text="ٱلرَّحْمَٰنِ ٱلرَّحِيمِ" />         <aya index="4" text="مَٰلِكِ يَوْمِ ٱلدِّينِ" />         <aya index="5" text="إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ" />         <aya index="6" text="ٱهْدِنَا ٱلصِّرَٰطَ ٱلْمُسْتَقِيمَ" />         <aya index="7" text="صِرَٰطَ ٱلَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ ٱلْمَغْضُوبِ عَلَيْهِمْ وَلَا ٱلضَّآلِّينَ" />     </sura>     ...(and basically, this style continues for the rest of the document) </quran>  

My aim is to use the loadDoc() function to return the data in the xml file, like so:

 function loadDoc(url) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () {     if (xhttp.readyState == 4 && xhttp.status == 200) {         return xhttp.responseText;     } }; xhttp.open("GET", url, true); xhttp.send(); }  

and then let the function below access specific nodes using the s and a parameters:

 function surah(s, a) {     s = s - 1;     xmlDoc = loadDoc("assets/xml/quran-uthmani.xml");     x = xmlDoc.getElementsByTagName('sura') + verse(a)[0];     return x.item(s).children[a].attributes[1].value + verse(a); }  

The function is then to be called in a php file to return select nodes from the quran-uthmani.xml file and display them on webpage.

This; however, throws the error: Uncaught TypeError: Cannot read property 'getElementsByTagName' of undefined and I seriously need help figuring this out.

No comments:

Post a Comment