none
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">
        <data>
            <element name="hello " value=" world"/>
            <element name="good " value=" morning"/>
        </data>
    </root>

    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="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/">
            <html>
                <head>
                    <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"/>
                </head>
                <body>
                    <form>
                        <xsl:for-each select="root/data">
                            <xsl:value-of select="element/@name"/><xsl:value-of select="element/@value"/><br />
                        </xsl:for-each>
                        <input type="button" value="click me" onclick="onMyClick();"/>
                    </form>
                </body>
            </html>
        </xsl:template>
    </xsl:stylesheet>

    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(xmlDoc.xml);
        alert("elements count: " + nodes.length);
        alert(document.body.innerHTML);
        alert(document.body.innerText);
    }
    function onMyClick() {
        alert(document.XMLDocument);
    }

    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:
    http://localhost[:port]/[webApplicationName]/MyTest.xml

    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

全部回复