Skip to content

Instantly share code, notes, and snippets.

@danfoust
Last active November 16, 2018 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danfoust/5b0690b112acd007baaecd7b2641cadd to your computer and use it in GitHub Desktop.
Save danfoust/5b0690b112acd007baaecd7b2641cadd to your computer and use it in GitHub Desktop.
Parse XML File
<!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