471,338 Members | 1,257 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

XML DOM in IE using Javascript

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>
Jul 23 '05 #1
2 2626
On Sat, 23 Apr 2005 14:51:50 -0700, in comp.lang.javascript Kenneth
<ja********@hotmail.com> wrote:
| 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.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #2


Kenneth wrote:
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Stumped and Confused | last post: by
2 posts views Thread by Jeronimo Bertran | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.