javascript - Include XML inline in a HTML file -
I am trying to include some (impressive) static XML data in an HTML file, and then click it Parsing with Testing the test below works fine in Firefox, Opera and Chrome (I get the list of nodes and hopes expected), but fails in IE8 (all the nodes are in the same depth, and the end tag nodes are included in the list ).
Q: How do I fix code to work in IE?
Code
& lt ;! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 Transitional // N" "http://www.w3.org/TR/html4/loose.dtd"> & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en" lang = "en" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Oh IE behavior - test case & lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Function p (text) {var out = document.getElementById ("output"); Out.innerHTML + = text + "& lt; br & gt;"; } Function walkDom (node, depth) {var i, il; If (node.net type === 1) {p ("node (" + depth + "):" + node.nodeName); If (node.childnode & node.childnodes.lamban> gt; {for (i = 0; i & lt; node.childNodes.length; i + = 1) {il = node.Childonodes [i]; WalkDom (IL, Depth + 1); }}}}} Function init () {var data = document.getElementById ("data"); WalkDom (data, 0); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body onload = "init ()" id = "body" & gt; & Lt; Div id = "data" style = "display: none" & gt; & Lt; Data & gt; & Lt; Ele & gt; & Lt; Foo & gt; Foo & lt; / Foo & gt; & Lt; Bars & gt; & Lt; / Bar & gt; & Lt; / Ele & gt; & Lt; / Data & gt; & Lt; / Div & gt; & Lt; Div id = "output" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt; "Right" output node (0): DIV node (1): data node (2): alley node (3): food node (3): bar
IE output
node (0): DIV node (1): data node (1): alley node (1): FOO node (1): / Food node 1): Bar node (1): / bar node (1): / al node (1): / data
It seems that your XML nodes have domain nodes Do not believe in it, while doing firefox, chrome and opera.
Of course, IE behaviors are correct, because these nodes are not part of the HTML DOM.
To answer your question - This behavior depends on how the navigation was implemented by the browser's authors and you use a "force" force to change it. .
In IE, there is a concept of XML embedded in HTML forms, which is called, maybe you can use it for IE.
Comments
Post a Comment