About document.XMLDocument RRS feed

  • 常规讨论

  • 1.Create a xml file named MyTest.xml. Then content is following:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="MyTest.xsl"?>
    <root title="My Xml + Xsl Test">
            <element name="hello " value=" world"/>
            <element name="good " value=" morning"/>

    2.Create a xsl file named MyTest.xsl. Then content is following:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="">
        <xsl:template match="/">
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <title><xsl:value-of select="root/@title"/></title>
                    <script type="text/javascript" src="MyTest.js"/>
                        <xsl:for-each select="root/data">
                            <xsl:value-of select="element/@name"/><xsl:value-of select="element/@value"/><br />
                        <input type="button" value="click me" onclick="onMyClick();"/>

    3.Create a javascript file named MyTest.js. Then content is following:
    window.onload = function() {
        xmlDoc = document.XMLDocument;
        var nodes = xmlDoc.selectNodes("//(element|group)");
        alert("elements count: " + nodes.length);
    function onMyClick() {

    4.Put the files of MyTest.xml and MyTest.xsl and MyTest.js in the root directory of our localhost web application,
    and access it using IE8 or IE6(When using IE6, we must install patch "WindowsXP-KB2559049-x86-ENU".
    If we don't install patch "WindowsXP-KB2559049-x86-ENU" for IE6, the follow strange scene is never happen,
    in other words. we can get the value of "document.XMLDocument" on the first access time),
    the url is following:

    Then we will find the following strage scene:
    The first access time, the result of javascript "document.XMLDocument" in "window.onload" function is null.
    After finishing page load, if we click "click me" button, the "document.XMLDocument" is still null.
    But when we don't close this page and click key "F5" or Refresh button of IE, we can get the value of "document.XMLDocument".
    Who can tell me the reason and the solution of getting the value of "document.XMLDocument" on the first access time,
    Thanks very much and best regards.

    2012年9月5日 2:55