Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  54] [ 2]  / answers: 1 / hits: 17689  / 12 Years ago, thu, august 23, 2012, 12:00:00

I am using the below code to read one xml file which is located locally. But its not displaying the object of xmldoc. My code is



function loadXMLDoc(XMLname)
{
var xmlDoc;
if (window.XMLHttpRequest)
{
xmlDoc=new window.XMLHttpRequest();
xmlDoc.open(GET,XMLname,false);
xmlDoc.send();
return xmlDoc.responseXML;
}

else if (ActiveXObject(Microsoft.XMLDOM))
{
xmlDoc=new ActiveXObject(Microsoft.XMLDOM);
xmlDoc.async=false;
xmlDoc.load(XMLname);
return xmlDoc;
}
alert(Error loading document!);
return null;
}



function f1()
{
var xmlDoc=loadXMLDoc(“test.xml”)
var M = xmlDoc.getElementsByTagName(“article”);
alert(M);
}


Its not displaying the alert if i call the function f1.Thanks in advance


More From » xml

 Answers
131

Better use Jquery function. Its working fine for me.



<script src=jquery.js type=text/javascript></script>
<script>
$(document).ready(function(){
$.ajax({
type: GET,
url: read2.xml,
dataType: xml,
success: function(xml) {
$(xml).find('site').each(function(){

var id = $(this).attr('id');
var title = $(this).find('title').text();
var url = $(this).find('url').text();
$(this).find('desc').each(function()
{
var brief = $(this).find('brief').text();
var long = $(this).find('long').text();
alert(my +brief );
alert(my +long );

});
});
}
});
});




And the XML file format will be





my title1
url1




brf 1
long 1




brf 2
long 2




[#83471] Tuesday, August 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevonmoisesf

Total Points: 693
Total Questions: 101
Total Answers: 128

Location: Reunion
Member since Mon, Dec 28, 2020
3 Years ago
kevonmoisesf questions
Sat, Jan 23, 21, 00:00, 3 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Jun 12, 19, 00:00, 5 Years ago
;