Need to display xml file in html div by using external JavaScript?

Can you clarify "external"? Is the xml file local? Here is something based on what I can infer...

<html>
<head>
<script>
    var http={
        init:   function()              { try {return new XMLHttpRequest();} catch (error) {} try {return new ActiveXObject("Msxml2.XMLHTTP");} catch (error) {} try {return new ActiveXObject("Microsoft.XMLHTTP");} catch (error) {} throw new Error("Could not create HTTP request object."); },
        get:    function(url)           { var h=this.init(); h.open("GET", url, false); h.withCredentials=true; h.send(null); return h.responseText; },
    }
    function load() {
        var xml=http.get('http://www.w3schools.com/xpath/books.xml');
        document.getElementById('div1').innerHTML=xml.replace(/</gim,'&lt;').replace(/>/gim,'&gt;');
    }
</script>
</head>
<body>
<input type=button onclick="load();" value="Load >" />
<div id=div1></div>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.