Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the count of Subtags inside another tag from XML file and display its elements using JavaScript
    text
    copied!<p>How to get the count of Subtags inside another tag from XML file and display its elements using JavaScript: This is my XML file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;pdfDetails&gt; &lt;Menu menuTitle="AllTools"&gt; &lt;pdf&gt; &lt;title&gt;Integrated Architecture&lt;/title&gt; &lt;description&gt;details&lt;/description&gt; &lt;fileName&gt;tools_selection_wizard.pdf&lt;/fileName&gt; &lt;imageName&gt;icon_Image.png&lt;/imageName&gt; &lt;/pdf&gt; &lt;pdf&gt; &lt;title&gt;Integrated Architecture Builder&lt;/title&gt; &lt;description&gt;details&lt;/description&gt; &lt;fileName&gt;integrated_architecture_builder.pdf&lt;/fileName&gt; &lt;imageName&gt;pdf_icon_Image.png&lt;/imageName&gt; &lt;/pdf&gt; &lt;pdf&gt; &lt;title&gt;ProposalWorks&lt;/title&gt; &lt;description&gt;details&lt;/description&gt; &lt;fileName&gt;proposal_works.pdf&lt;/fileName&gt; &lt;imageName&gt;pdf_icon_Image.png&lt;/imageName&gt; &lt;/pdf&gt; &lt;pdf&gt; &lt;title&gt;Cross&lt;/title&gt; &lt;description&gt;details&lt;/description&gt; &lt;fileName&gt;works.pdf&lt;/fileName&gt; &lt;imageName&gt;pdf_icon_Image.png&lt;/imageName&gt; &lt;/pdf&gt; &lt;pdf&gt; &lt;title&gt;Integrated Architecture Videos&lt;/title&gt; &lt;description&gt;details&lt;/description&gt; &lt;fileName&gt;integrated_architecture_videos.pdf&lt;/fileName&gt; &lt;imageName&gt;pdf_icon_Image.png&lt;/imageName&gt; &lt;/pdf&gt; &lt;/Menu&gt; &lt;Menu menuTitle="Discover"&gt; &lt;pdf&gt; &lt;title&gt;Integrated&lt;/title&gt; &lt;description&gt;details&lt;/description&gt; &lt;fileName&gt;integrated_architecture.pdf&lt;/fileName&gt; &lt;imageName&gt;pdf_icon_Image.png&lt;/imageName&gt; &lt;/pdf&gt; &lt;pdf&gt; &lt;title&gt;Integrated Architecture Videos&lt;/title&gt; &lt;description&gt;details&lt;/description&gt; &lt;fileName&gt;integrated_architecture_videos.pdf&lt;/fileName&gt; &lt;imageName&gt;pdf_icon_Image.png&lt;/imageName&gt; &lt;/pdf&gt; &lt;pdf&gt; &lt;title&gt;Podcasts&lt;/title&gt; &lt;description&gt;details&lt;/description&gt; &lt;fileName&gt;pod_casts.pdf&lt;/fileName&gt; &lt;imageName&gt;pdf_icon_Image.png&lt;/imageName&gt; &lt;/pdf&gt; &lt;/Menu&gt; &lt;/pdfDetails&gt; </code></pre> <p>In first Menu tag pdf tags are 5 and in second its 3.How to get the count and display there elements in a table view format. This is what I have done till now but Its not fetching the data</p> <pre><code>&lt;script type="text/javascript"&gt; function parseXML(){ xmlDoc=loadXMLDoc("Details.xml"); mnu=xmlDoc.getElementsByTagName("Menu"); var mnucount=mnu.length pdf=xmlDoc.getElementsByTagName("pdf"); var pdfcount=pdf.length if(mnucount&gt;=1){ alert(mnucount); for(i=0;i&lt;mnucount;i++){ //xmlDoc.getElementsByTagName("title")[j].childNodes[0]; '&lt;br&gt;' if(pdfcount&gt;=1){ alert(pdfcount); var str = '&lt;table border="1"&gt;'; str+='&lt;tr&gt;&lt;td&gt;title&lt;/td&gt;&lt;td&gt;description&lt;/td&gt;&lt;td&gt;fileName&lt;/td&gt;&lt;td&gt;imageName&lt;/td&gt;&lt;/tr&gt;'; for(j=0;j&lt;pdfcount;j++){ p=xmlDoc.getElementsByTagName("title")[j].childNodes[0]; txttitle=p.nodeValue; q=xmlDoc.getElementsByTagName("description")[j].childNodes[0]; txtdescription=q.nodeValue; r=xmlDoc.getElementsByTagName("fileName")[j].childNodes[0]; txtfileName=r.nodeValue; s=xmlDoc.getElementsByTagName("imageName")[j].childNodes[0]; txtimageName=s.nodeValue; str=str+'&lt;tr&gt;&lt;td&gt;'+txttitle+'&lt;/td&gt;&lt;td&gt;'+txtdescription+'&lt;/td&gt;&lt;td&gt;'+txtfileName+'&lt;/td&gt;&lt;td&gt;'+txtimageName+'&lt;/td&gt;&lt;/tr&gt;'; } str+='&lt;/table&gt;'; document.getElementById('data').innerHTML = str; } } } } function loadXMLDoc(dname){ if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // Internet Explorer { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(); return xhttp.responseXML; } &lt;/script&gt; </code></pre> <p>This is not fetching anything.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload