<script type="text/javascript">
if (window.XMLHttpRequest)
{ my_xml=new XMLHttpRequest();
}
else
{
my_xml=new ActiveXObject("Microsoft.XMLHTTP");
}
/////////////////////////////
my_xml.open("GET",'../php_tutorial/xml-sample3.xml',false);
my_xml.send();
xml_str=my_xml.responseXML;
var x=xml_str.getElementsByTagName("address"); // 1
document.write(x[0].getAttribute('type'));
</script>
To display all the attributes we have to use for loop.
for(i=0;i<x.length;i++){
document.write(x[i].getAttribute('type')); // working
document.write('<br>');
} Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.