/    Sign up×
Community /Pin to ProfileBookmark

Help: loading XML client-side

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

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @markem spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...