<html>
<head>
<script type="application/javascript;version=1.7">
var req = new XMLHttpRequest();
req.open("GET","file:///Users/me/folder/items.xml", false);
req.send(null);
var dom = req.responseXML;
</script>
</head>
<body>
</body>
</html>
Above is the code that is given to me – I am supposed to pull objects from items.xml and inject them into the body of this file.
How would I go about doing this?
The
.responseXMLproperty is a document object*[1], which represent the document tree of your parsed XML object. The.appendChildcan be used to append nodes from the XML document to your body:It’s also possible to select a specific element of the XML tree, using DOM methods/properties, such as
.getElementsByTagName("tag_name"),.childNodes, etc.If you prefer a string, use
.xml(IE) orXMLSerializerto get a string representation of the document:*1 The
.responseXMLwill benullif the response is invalid.