document.load()

David Joham djoham at yahoo.com
Mon Jun 23 04:10:42 BST 2003


--- Peter Kelly <pmk at kde.org> wrote:
> Due to popular demand, document.load() has now been implemented. 

Peter, you rock!

I've looked at the test suites and it seems like pretty much everything is there. I have however
found a problem with the getElementsByTagName function. Would you mind looking at the following
code and seeing if you can determine why the call to getElementsByTagName is failing? The code
works OK in Mozilla.


<html>
<body>
<div id="container" style="background-color:yellow"></div>

<script>
//load xml file
var xmlDoc= document.implementation.createDocument("","doc",null);
xmlDoc.async = false;
xmlDoc.onload = getdaily;
xmlDoc.load("dailynews.xml");

//Regular expression used to match any non-whitespace character
var notWhitespace = /\S/


function getdaily(){
  //Cache "messages" element of xml file
  var msgobj=xmlDoc.getElementsByTagName("messages");
  alert("The number of nodes returned was:\n" + msgobj.length + "\nIt should be 1");
  msgobj = msgobj[0];
  
  alert("As a sanity check, the number\nof DIVs found in the document\n" +
        "(using document.getElementsByTagName)\n was " + 
        document.getElementsByTagName("div").length +
        ".\n It should be 1");
  
  //REMOVE white spaces in XML file. Intended mainly for NS6/Mozilla
  for (i=0;i<msgobj.childNodes.length;i++){
    if ((msgobj.childNodes[i].nodeType == 3)&& 
        (!notWhitespace.test(msgobj.childNodes[i].nodeValue))) {
      // that is, if it's a whitespace text node
      msgobj.removeChild(msgobj.childNodes[i])
      i--
    }
  }
  
  var dateobj=new Date()
  var today=dateobj.getDay() //returns 0-6. 0=Sunday
  
  //Get today's message and display it in DIV:
  document.getElementById("container").innerHTML=
    xmlDoc.getElementsByTagName("messages")[0].childNodes[today].firstChild.nodeValue
}


</script>
I should be displaying the day of the week.

</body>
</html>


The XML file is the following:

<?xml version="1.0"?>
<messages>
<daily>Today is Sunday.</daily>
<daily>Today is Monday.</daily>
<daily>Today is Tuesday.</daily>
<daily>Today is Wednesday.</daily>
<daily>Today is Thursday.</daily>
<daily>Today is Friday.</daily>
<daily>Today is Saturday.</daily>
</messages>


I hope this example isn't too contrived. I found it on the net at
http://javascriptkit.com/dhtmltutors/getxml3.shtml and tried to get it to work.


Thanks again for implementing this!


Best regards,

David

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com




More information about the kfm-devel mailing list