fishbaitfood Posted October 29, 2011 Share Posted October 29, 2011 Hello guys, I want to make an xml feed into my webpage, but the xml is generated from an .asp file on another website, so it's not actually an xml file, but xml output. Now, I want to retrieve this xml output on my webpage, but I'm having difficulties while doing this. What I've tried so far: - With PHP: <?php echo file_get_contents("http://link-on-other-website.asp?XML=1"); ?> - With javascript: <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://link-on-other-website.asp?XML=1", false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("RECORD"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x[i].getElementsByTagName("DATE")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); </script> When using the PHP code, I can retrieve it obviously, but I get an <?xml ... > declaration within my body, which is not allowed. When using the Javascript code, I can't even retrieve anything. And the goal is to style this xml output to match my website. That's the whole purpose of this xml link, because I couldn't style the iframe I had earlier. Can someone help me on this, on how to properly embed this asp generated xml output, within my HTML5 document? ps: I've asked for the xml-feed link from that other website, so using the above PHP code is legit in my case. Quote Link to comment Share on other sites More sharing options...
fishbaitfood Posted October 29, 2011 Author Share Posted October 29, 2011 Bump. :-\ Is there any other way to retrieve the XML output? Which lets me style it the way I want? Quote Link to comment Share on other sites More sharing options...
trq Posted October 30, 2011 Share Posted October 30, 2011 I would use simplexml_load_file to load the file into an object, then from that object create HTML which could be formatted however you want. Quote Link to comment Share on other sites More sharing options...
fishbaitfood Posted October 30, 2011 Author Share Posted October 30, 2011 Thanks thorpe! Just what I needed! So many useful PHP functions I haven't discovered yet... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.