问题描述
在w3school网站上有两个教程:
In the w3school site there are two tutorials:
我想知道他们的相关性,因为我认为HTML DOM是一种XML DOM。
I want to know the releationship of them, since I think the HTML DOM is one kind of XML DOM.
所以XML DOM中的方法/属性可以在HTML DOM中使用,HTML DOM可能拥有一些特殊的方法。
So the methods/properties in the XML DOM can be used in HTML DOM, and the HTML DOM may own some special methods.
但是,当我尝试使用它:
However, when I try to use this:
HTML:
<span id="con">xxx</span>
var a=document.createElement("a");
document.getElementById("con").appendChild(a);
在IE中无效。
所以我不知道是什么问题?
So I wonder what is the problem?
推荐答案
DOM指的是你使用XML制作的树。树由节点组成。例如:
DOM refers to a tree you make out of XML. The tree is made up of nodes. For example:
<a x="bb">
<b> text </b>
</a>
变成一个有三个节点的树:一个用于 a
和一个 b
和一个文本。节点包含属性作为字段。所以 a
节点将有一个字段: x =bb
。
turns into a tree with three nodes: one for a
and one for b
and one for the text. The nodes contains the attributes as fields. So the a
node will have a field: x="bb"
.
HTML是(实际上)XML,所以你可以从中构建一个DOM树。 HTML只是具有预定义元素的XML。也就是说,您不能使用任何您想要的元素名称(您不能使用< children>
,< ball>
,...),您可以使用预定义的名称( a
, span
, div
,...)。
HTML is (practically) XML so you can build a DOM tree out of it. HTML is just XML with predefined elements. I.e., you can't use whatever names you want for your elements (you can't use <children>
, <ball>
,...) you can use the predefined names (a
, span
, div
, ...).
我说实际,因为HTML通常是破碎的XML(例如使用< br>
是错误的XML你应该使用< br />
代替)。浏览器具有智能解析器,可以知道如何克服这个破坏的XML,并从HTML中创建一个可用的树。
I say "practically" because HTML is usually broken XML (for example using <br>
is wrong XML. you should use <br />
instead). The browsers have smart parsers that know how to overcome this broken XML and make a usuable tree out of the HTML.
这篇关于HTML DOM和XML DOM有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!