为什么在DOM中Attr继承自Node?

Why does Attr inherit from Node in the DOM?

根据the DOM Core,

Attr objects inherit the Node interface, but since they are not actually child nodes of the element they describe, the DOM does not consider them part of the document tree.

还有

The DOM takes the view that attributes are properties of elements rather than having a separate identity from the elements they are associated with

鉴于此,Attr 对象继承自 Node 的优点是什么?

DOM Spec 状态:

Attr nodes participate in a tree for historical reasons; they never have a (non-null) parent or any children and are therefore alone in a tree.

这是一个部分答案,但我想知道是否有人对 AttrNode 继承和树参与有比简单的“历史原因”更深入的解释。

抱歉,如果这是一个重复的问题,我发现的大多数问题都围绕着 Attr 对象的行为,而不是其结构背后的基本原理。

对于“为什么”的问题,你要非常清楚自己是不是在问

  • 这个决定的潜在好处是什么?或者

  • 从历史上看,提出了哪些论点以及为什么个别委员会成员以他们的方式投票(如果确实进行了讨论和投票)?

在大多数情况下,第二个问题是无法回答的,但在少数情况下(例如 Tim Bray 的注释 XML 规范)您至少可以看到其中一位编辑提出的基本原理。

对我来说,这个决定就像是一种妥协。属性与其他节点有许多共同的属性,因此让它们实现相同的接口是有好处的;但是有一些你并不真正想要的包袱,因为它可能会增加不必要的成本,比如在包含元素上有一个 link。

坦率地说,DOM不是一个好的设计,很难说它为什么会犯这么多设计错误,除了它是一个委员会匆忙拼凑起来的。 JDOM 和 XOM 等后期型号要好得多,但遗憾的是 Javascript.

不可用