This is my first experience with XML. I’ve been reading through the XML DOM section on this website and have been trying to use the examples provided, but I keep getting errors trying to step through (even just read) the data. Scenario: I’m trying to provide a way to import an XML file (formatted for Excel) from the corporate intranet, place the data into existing HTML input elements for quality control, then save the data to a database. My JS is just enough to be dangerous. I would GREATLY appreciate any help!
My testing data file in its entirety contains:
<Employee>
<ID>6880</ID>
</Employee>
Here is my code:
function importXML(fieldName)
{
fileName = document.forms[0].elements[fieldName].value;
xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) parseXML()
};
xmlDoc.loadXML(fileName);
}
function parseXML()
{
document.write(“<br>Error Code: “);
document.write(xmlDoc.parseError.errorCode);
document.write(“<br>Error Reason: “);
document.write(xmlDoc.parseError.reason);
document.write(“<br>Error Line: “);
document.write(xmlDoc.parseError.line);
var doc=xmlDoc.documentElement;
var x = xmlDoc.getElementsByTagName(‘Employee’);
}
</script>
<form method=”POST”
enctype=”multipart/form-data”
action=”saveFile.asp”>
<input type=”file” name=”fileName” size=”60″>
<input type=”submit” VALUE=”Load File” onClick=”importXML(‘fileName’)”>
</form>
Script Error: “Object required”
Output:
Error Code: -1072896682
Error Reason: Invalid at the top level of the document.
Error Line: 1