Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 2.40 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Javascript - Unable to get data from a nested XML file - Cannot read property of null
  2. <?xml version="1.0" encoding="ISO-8859-1"?>
  3. <mediaGroup>
  4.   <amgVersion version="1.3" />
  5.   <groupInfo>
  6.     <bunch of="data I don't care about" />
  7.   </groupInfo>
  8.   <sizes>
  9.     <bunch of="data I don't care about" />
  10.   </sizes>
  11.  
  12.   <media totalGallerySize="104">
  13.     <item>
  14.       <title></title>
  15.       <description>Yo! Look at that monkey on the bars</description>
  16.       <imageID />
  17.       <mediaType/>
  18.       <renditions>
  19.         <rendition size="large" />
  20.         <rendition size="medium" />
  21.         <rendition size="small" />
  22.         <rendition size="thumb"  />
  23.       </renditions>
  24.     </item>
  25.     <item>
  26.       <title></title>
  27.       <description>It's trying to parse XML files ahhaha</description>
  28.       <imageID />
  29.       <mediaType/>
  30.       <renditions>
  31.         <rendition size="large" />
  32.         <rendition size="medium" />
  33.         <rendition size="small" />
  34.         <rendition size="thumb"  />
  35.       </renditions>
  36.     </item>
  37.     <item>
  38.       <title></title>
  39.       <description></description>
  40.       <imageID />
  41.       <mediaType/>
  42.       <renditions>
  43.         <rendition size="large" />
  44.         <rendition size="medium" />
  45.         <rendition size="small" />
  46.         <rendition size="thumb"  />
  47.       </renditions>
  48.     </item>
  49.     <item>
  50.       <title></title>
  51.       <description>That missing description is going to make him angry</description>
  52.       <imageID />
  53.       <mediaType/>
  54.       <renditions>
  55.         <rendition size="large" />
  56.         <rendition size="medium" />
  57.         <rendition size="small" />
  58.         <rendition size="thumb"  />
  59.       </renditions>
  60.     </item>  
  61.   </mediaGroup>
  62.        
  63. <script type="text/javascript">
  64.   function loadXMLDoc(dname) {
  65. if (window.XMLHttpRequest)
  66.     {
  67.     xhttp=new XMLHttpRequest();
  68.     }
  69. else
  70.     {
  71.     xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  72.     }
  73. xhttp.open("GET",dname,false);
  74. xhttp.send();
  75. return xhttp.responseXML;
  76.   } //end function
  77.  
  78.   xmlDoc=loadXMLDoc("group.xml");
  79.   var z=xmlDoc.getElementsByTagName("item"), nameELEM;
  80.   document.write(z.length);
  81.   for (i=0;i<=z.length;i++){
  82.     nameELEM=z[i].getElementsByTagName("description")[0];
  83.     if (typeof nameELEM.firstChild.data !== "undefined") { //This is the line the error quotes
  84.       //handle property xxx of documentFragment as required
  85.       document.write(nameELEM.firstChild.data + "<br />");
  86.     }
  87.   }
  88.  </script>
  89.        
  90. if (nameELEM.firstChild.data !== null)