Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot display XML data on HTML file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have the following code here and I can't seem to load the XML document into my HTML file. What seems to be the problem?

<html>
<head>

<script language=&quot;JavaScript&quot;>
<!--
var RootElement1;
var xmlDoc1=new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
xmlDoc1.load(&quot;simple.xml&quot;);

function StartUp() {
if (xmlDoc1.readyState==&quot;4&quot;) {
StartLoading();
}
else {
alert(&quot;Loading operation could not start &quot; + xmlDoc1.readyState);
}
}

function StartLoading() {
RootElement1=xmlDoc1.documentElement;
todata.innerText=RootElement1.childNodes(0).text;
fromdata.innerText=RootElement1.childNodes(1).text;
subjectdata.innerText=RootElement1.childNodes(2).text;
bodydata.innerText=RootElement1.childNodes(3).text;
}
//-->
</script>
</head>

<body bgcolor=&quot;ffffff&quot; onload=&quot;StartUp()&quot;>
TO:  <span id=&quot;todata&quot;></span><br>
FROM:  <span id=&quot;fromdata&quot;></span><br>
SUBJECT:  <span id=&quot;subjectdata&quot;></span><br>
BODY:  <span id=&quot;bodydata&quot;></span><br>
</body>
</html>
 
Hi!
I have tried your code in MS IE
with following simple.xml file
and it was working.

simple.xml
Code:
<message>
	<to>To Sneik 35</to>
	<from>Me</from>
	<subject>Subj is ... </subject>
	<body>The body is ...</body>
</message>

the result was:

TO: To Sneik 35
FROM: Me
SUBJECT: Subj was ...
BODY: The body is ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top