unable to parse xml with javascript loadXMLString()

jackass9929

New Member
I am trying to parse the xml file from a webservice. I am using javascript loadXMLString function to parse the xml into html. with local file it was working fine if i insert the xml code in to a variable. but for getting xml from external link i have used php function here like this:\[code\]<?php $request = "http://www.somewebsite.com/feeds/get-cities.php?vendor_key=xxx";$response = file_get_contents($request);$xmlstring = htmlspecialchars($response, ENT_QUOTES);?><script language="javascript">function loadXMLString(txt) {if (window.DOMParser){ parser=new DOMParser(); xmlDoc=parser.parseFromString(txt,"text/xml");}else // Internet Explorer{ xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.loadXML(txt); }return xmlDoc;}//function loadXMLString endstext = <?php $xmlstring;?>xmlDoc=loadXMLString(text);document.write("<table border='1'>");var x=xmlDoc.getElementsByTagName("city");for (i=0;i<x.length;i++){ document.write("<tr style='background:#dddddd;'><td>"); document.write(x.getElementsByTagName("name")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x.getElementsByTagName("country")[0].childNodes[0].nodeValue); document.write("</td></tr>");}document.write("</table>");</script>\[/code\]in the above code i am trying to insert the xml code from a php variable $xmlstring to javascript variable text. but it display nothing. but if i put the xml code inside the script like below it works perfectly:\[code\]text="<cities>"text=text+"<city>";text=text+"<name>bulga</name>";text=text+"<country>Giada De Laurentiis</country>";text=text+"<city_id>2005</city_id>";text=text+"</city>";text=text+"</cities>";\[/code\]does any body know how can i parse it. or if somebody have a better solution please suggest me that also.
 
Back
Top