📄 dom_mozilla_vs_ie.asp@output=print
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XML DOM Browser Differences</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
<h1>XML DOM Browser Differences</h1>
<a href="dom_nodes_traverse.asp"><img border="0" src="../images/btn_previous.gif" alt="prev" width="100" height="20" /></a>
<a href="dom_nodes_navigate.asp"><img border="0" src="../images/btn_next.gif" alt="next" width="100" height="20" /></a>
<hr />
<p class="intro">Different browsers handle empty text nodes in the XML DOM
differently.</p>
<hr />
<h2>Examples
</h2>
<p>The examples below use the XML file
<a target="_blank" href="books.xml">books.xml</a>. <br />
A function, <a href="dom_loadxmldoc.asp">loadXMLDoc()</a>, in an external JavaScript is used to load the XML file.</p>
<p><a target="_blank" href="tryit.asp@filename=try_dom_nodetype_ievsmozilla">
Display the length of a node list</a><br />
This example shows the length of a node list. The result is different in
Internet Explorer and other browsers</p>
<p><a target="_blank" href="tryit.asp@filename=try_dom_nodetype_ievsmozilla2">
Ignore empty text between nodes</a><br />
This example checks the nodeType of the nodes and only processes element nodes</p>
<hr />
<h2>Browser Differences in DOM Parsing</h2>
<p>All modern browsers support the W3C DOM specification.</p>
<p>However, there are some differences
between browsers. Two important differences are:</p>
<ul>
<li>The way they load XML</li>
<li>The way they handle white-spaces and new lines</li>
</ul>
<p>The different ways to load XML is explained in the chapter "<a href="dom_parser.asp">DOM
Parser</a>".</p>
<p>The different ways to handle white spaces and new lines is explained in this
chapter.</p>
<hr />
<h2>DOM - White Spaces and New Lines</h2>
<p>XML often contains new line, or white space characters, between nodes. This
is often the case when the document is edited by a simple editor like Notepad. </p>
<p>The following example (edited by Notepad) contains CR/LF (new line) between
each line and two spaces in front of each child node: </p>
<table width="100%" border="1" class="ex" cellspacing="0" id="table28">
<tr>
<td>
<pre><book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book></pre>
</td>
</tr>
</table>
<p>Firefox, and some other browsers, will treat empty white-spaces or new lines
as text nodes, Internet Explorer will not</p>
<p>The following code fragment displays how many child nodes the root element
(of books.xml) has:</p>
<table width="100%" border="1" class="ex" cellspacing="0" id="table21">
<tr>
<td>
<pre>xmlDoc=loadXMLDoc("books.xml");</pre>
<pre>x=xmlDoc.documentElement.childNodes;
document.write("Number of child nodes: " + x.length);</pre>
</td>
</tr>
</table>
<p>Example explained:</p>
<ol>
<li>Load "<a target="_blank" href="books.xml">books.xml</a>"
into xmlDoc using <a href="dom_loadxmldoc.asp">loadXMLDoc()</a> </li>
<li>Get the child nodes of the root element</li>
<li>Output the number of child nodes. The result is different depending on
which browser you use. Firefox will alert 9 child nodes, while Internet
Explorer will alert 4.</li>
</ol>
<p><a target="_blank" href="tryit.asp@filename=try_dom_nodetype_ievsmozilla">Try
it yourself</a></p>
<hr />
<h2>Ignore Empty Text Between Elements</h2>
<p>To ignore empty text nodes between element nodes, you can check the node type. An element node
has type 1:</p>
<table width="100%" border="1" class="ex" cellspacing="0" id="table27">
<tr>
<td>
<pre>xmlDoc=loadXMLDoc("books.xml");</pre>
<pre>x=xmlDoc.documentElement.childNodes;</pre>
<pre>for (i=0;i<x.length;i++)
{
if (x[i].nodeType==1)
{// only process element nodes
document.write(x[i].nodeName);
document.write("<br />");
}
}</pre>
</td>
</tr>
</table>
<p>Example explained:</p>
<ol>
<li>Load "<a target="_blank" href="books.xml">books.xml</a>"
into xmlDoc using <a href="dom_loadxmldoc.asp">loadXMLDoc()</a> </li>
<li>Get the child nodes of the root element</li>
<li>For each child node, check the node type of the node. If the node type
is "1" it is an element node</li>
<li>Output the name of the node if it is an element node</li>
</ol>
<p><a target="_blank" href="tryit.asp@filename=try_dom_nodetype_ievsmozilla2">
Try it yourself simple</a> or
<a target="_blank" href="tryit.asp@filename=try_dom_nodetype_ievsmozilla3">Try it yourself
full</a></p>
<hr />
<a href="dom_nodes_traverse.asp"><img border="0" src="../images/btn_previous.gif" alt="prev" width="100" height="20" /></a>
<a href="dom_nodes_navigate.asp"><img border="0" src="../images/btn_next.gif" alt="next" width="100" height="20" /></a>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -