Last active
November 16, 2018 19:10
-
-
Save danfoust/5b0690b112acd007baaecd7b2641cadd to your computer and use it in GitHub Desktop.
Parse XML File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Parse XML</title> | |
<script> | |
function getXML(fileUrl) | |
{ | |
var xmlHTTP = new XMLHttpRequest(); | |
try { | |
xmlHTTP.open("GET", fileUrl, false); | |
xmlHTTP.send(null); | |
} | |
catch (e) { | |
window.alert("Unable to load the requested file."); | |
return; | |
} | |
return xmlHTTP.responseText; | |
} | |
</script> | |
</head> | |
<body> | |
<script> | |
var fileUrl = 'path/to/xml_file'; | |
var xml = getXML(fileUrl); | |
var parser = new DOMParser(); | |
var xmlDoc = parser.parseFromString(xml,"text/xml"); | |
console.log(xmlDoc); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment