Help: Using XMLDOM

webmasterbeta

New Member
First off, I apologize to those who will recognize this post from the JavaScript forum. I'm posting it here because there haven't been any responses there. And I do need the help.

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. I've tried consolidating the methods (using xmlDoc.async="false") and I still get errors. 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 knowledge is just enough to be dangerous - in other words I'm no expert. 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=http://www.webdeveloper.com/forum/archive/index.php/"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
 
Back
Top