October 8, 201214 yr Right, Below is a simple javascript request to display the content that is in the XML document. I have lot's of different versions of XML's that are all from the same place but some are structured slightly different, so some elements inside the KISCOURSE tag do not have a TITLE - when this happens it throws out my coding structure and makes it appear wrong. Is there a way, if TITLE is not found inside a KISCOURSE, then do not display that KISCOURSE and just move onto the next one. Just incase, For an example on how the XML Data looks, see: http://universitycompare.com/wp-content/themes/blue-and-grey/XML/london_metropolitan_university.xml <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","http://universitycompare.com/wp-content/themes/blue-and-grey/XML/london_metropolitan_university.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; var x=xmlDoc.getElementsByTagName("INSTITUTION"); for (i=0;i<x.length;i++) var x=xmlDoc.getElementsByTagName("KISCOURSE"); for (i=0;i<x.length;i++) { document.write("<div class='CourseArea'><h3 id='CourseTitle'>"); // TITLE document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); document.write("</h3>"); document.write("<p class='ForP'>- "); document.write(x[i].getElementsByTagName("MODE")[0].childNodes[0].nodeValue); document.write("</p><div class='clear'></div>"); // UCAS CODE document.write("<p id='ucascode'>"); document.write("<b>UCAS CODE</b> "); document.write(x[i].getElementsByTagName("UCASCOURSEID")[0].childNodes[0].nodeValue); document.write("</p>"); // READ MORE LIGHTBOX document.write("<img src='<?php echo home_url(); ?>/wp-content/themes/blue-and-grey/images/info-icon.png' width='15' style='margin:0px 2px 0px -4px;' />"); document.write("<a class='various' href='#ReadMore'>Read More</a> "); // VISIT COURSE LINK document.write("<a class='courselink' href='"); document.write(x[i].getElementsByTagName("CRSEURL")[0].childNodes[0].nodeValue); document.write("' target='_blank'>Visit course website</a>"); document.write("</div>"); } </script>
October 9, 201214 yr Author Why not use XSLT? haven't really dove into XSLT to see what it's like, and the information that I receive each year will be XML, figured it would be easier to sort or is easy to convert over to XSLT?
Create an account or sign in to comment