- Javascript - Unable to get data from a nested XML file - Cannot read property of null
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <mediaGroup>
- <amgVersion version="1.3" />
- <groupInfo>
- <bunch of="data I don't care about" />
- </groupInfo>
- <sizes>
- <bunch of="data I don't care about" />
- </sizes>
- <media totalGallerySize="104">
- <item>
- <title></title>
- <description>Yo! Look at that monkey on the bars</description>
- <imageID />
- <mediaType/>
- <renditions>
- <rendition size="large" />
- <rendition size="medium" />
- <rendition size="small" />
- <rendition size="thumb" />
- </renditions>
- </item>
- <item>
- <title></title>
- <description>It's trying to parse XML files ahhaha</description>
- <imageID />
- <mediaType/>
- <renditions>
- <rendition size="large" />
- <rendition size="medium" />
- <rendition size="small" />
- <rendition size="thumb" />
- </renditions>
- </item>
- <item>
- <title></title>
- <description></description>
- <imageID />
- <mediaType/>
- <renditions>
- <rendition size="large" />
- <rendition size="medium" />
- <rendition size="small" />
- <rendition size="thumb" />
- </renditions>
- </item>
- <item>
- <title></title>
- <description>That missing description is going to make him angry</description>
- <imageID />
- <mediaType/>
- <renditions>
- <rendition size="large" />
- <rendition size="medium" />
- <rendition size="small" />
- <rendition size="thumb" />
- </renditions>
- </item>
- </mediaGroup>
- <script type="text/javascript">
- function loadXMLDoc(dname) {
- if (window.XMLHttpRequest)
- {
- xhttp=new XMLHttpRequest();
- }
- else
- {
- xhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xhttp.open("GET",dname,false);
- xhttp.send();
- return xhttp.responseXML;
- } //end function
- xmlDoc=loadXMLDoc("group.xml");
- var z=xmlDoc.getElementsByTagName("item"), nameELEM;
- document.write(z.length);
- for (i=0;i<=z.length;i++){
- nameELEM=z[i].getElementsByTagName("description")[0];
- if (typeof nameELEM.firstChild.data !== "undefined") { //This is the line the error quotes
- //handle property xxx of documentFragment as required
- document.write(nameELEM.firstChild.data + "<br />");
- }
- }
- </script>
- if (nameELEM.firstChild.data !== null)