XML DOM in IE using Javascript

K

Kenneth

I am tryint to view a xml document in Internet Exploer as a ActiveX
object using Javascript but it does not work. I only see the button
but nothing happens when i click it. I am trying to view the
'firstChild' of the xml document.

here is the code;
----------------------------------------------------------------


<html>
<head>
<script language="javascript">
<!--
function alert()
{

var xmldoc, meetingsNode, meetingNode;
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.load("members.xml");
document.write("works so far");

meetingsNode = xmldoc.documentElement;
document.write("works so far");


meetingNode = meetingsNode.firstChild;
//does not process after this line

document.writeln(meetingNode);

}
//-->
</script>



<title>Read Members.xml</title>


</head>

<body>

<input type="button" name="submit" onclick="alert()" />



</body>
</html>
 
J

Jeff North

| I am tryint to view a xml document in Internet Exploer as a ActiveX
| object using Javascript but it does not work. I only see the button
| but nothing happens when i click it. I am trying to view the
| 'firstChild' of the xml document.
|
| here is the code;
| ----------------------------------------------------------------
| <html>
| <head>
| <script language="javascript">
| <!--
| function alert()
| {
| var xmldoc, meetingsNode, meetingNode;
| xmldoc = new ActiveXObject("Microsoft.XMLDOM");
| xmldoc.load("members.xml");
| document.write("works so far");
| meetingsNode = xmldoc.documentElement;
| document.write("works so far");
| meetingNode = meetingsNode.firstChild;
| //does not process after this line
| document.writeln(meetingNode);
| }
| //-->
| </script>
|
| <title>Read Members.xml</title>
| </head>
| <body>
| <input type="button" name="submit" onclick="alert()" />
| </body>
| </html>

alert is a predefined javascript function. You might give your
function another name i.e. xalert() and see what happens.
 
M

Martin Honnen

Kenneth said:
I am tryint to view a xml document in Internet Exploer as a ActiveX
object using Javascript but it does not work. I only see the button
but nothing happens when i click it. I am trying to view the
'firstChild' of the xml document.
var xmldoc, meetingsNode, meetingNode;
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.load("members.xml");
document.write("works so far");

Loading happens asynchronously by default so you either need an
onreadystatechange handler e.g.

var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
xmlDocument.onreadystatechange = function () {
if (xmlDocument.readyState == 4) {
alert(xmlDocument.xml);
}
};
xmlDocument.load('test2005042301.xml');

or you need to load synchronously

var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
xmlDocument.async = false;
var wellFormed = xmlDocument.load('test2005042301.xml');
if (wellFormed) {
alert(xmlDocument.xml);
}

but inside the browser synchronous loading blocks the user agent so that
you would better use asynchronous loading as described above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top