加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – DOM splitText和normalize组合应该给出身份吗?

发布时间:2020-12-16 00:01:40 所属栏目:百科 来源:网络整理
导读:昨天我卷入了关于DOM实现怪癖的讨论,引发了一个关于Text.splitText和Element.normalise行为以及它们应该如何表现的有趣问题. 在DOM Level 1 Core中,Text.splitText被定义为…… Breaks this Text node into two Text nodes at the specified offset,keeping
昨天我卷入了关于DOM实现怪癖的讨论,引发了一个关于Text.splitText和Element.normalise行为以及它们应该如何表现的有趣问题.

在DOM Level 1 Core中,Text.splitText被定义为……

Breaks this Text node into two Text nodes at the specified offset,keeping both in the tree as siblings. This node then only contains all the content up to the offset point. And a new Text node,which is inserted as the next sibling of this node,contains all the content at and after the offset point.

标准化是……

Puts all Text nodes in the full depth of the sub-tree underneath this Element into a “normal” form where only markup (e.g.,tags,comments,processing instructions,CDATA sections,and entity references) separates Text nodes,i.e.,there are no adjacent Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded,and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.

所以,如果我采用一个包含“Hello World”的文本节点,在textNode中引用,并且执行

textNode.splitText(3)

textNode现在具有内容“Hello”,以及包含“World”的新兄弟

如果我那么

textNode.parent.normalize()

什么是textNode?该规范没有明确表示textNode仍然是它的前一个父节点的子节点,只是更新为包含所有相邻的文本节点(然后被删除).它似乎是一个删除所有相邻文本节点的一个conforment行为,然后重新创建一个具有值的串联的新节点,使textNode指向不再是树的一部分的东西.或者,我们可以以与splitText相同的方式更新textNode,因此它保留了它的树位置,并获得了一个新值.

行为的选择实际上是完全不同的,我无法找到关于哪个是正确的澄清,或者这只是规范中的疏忽(它似乎在2级或3级似乎没有澄清).任何DOM / XML专家都可以解决这个问题吗?

我早期就在DOM工作组工作;我确信我们的意思是textNode包含新的连接值,但是如果我们没有在规范中说出来,那么某些实现可能会创建一个新节点而不是重用textNode,尽管这需要更多的工作.实现者.

如有疑问,请采取防御措施.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读