element.cloneNode(true)(深度克隆)的效率如何?

发布于 07-07 21:18 字数 393 浏览 10 评论 0原文

我正在 XML DOM 对象中构建 HTML 代码,以用作使用 XSL 模板的 div 元素的 innerHTML 的内容。 传统上,我们创建一个新的 XML DOM 文档,并将输入参数添加为 XML 元素,以便通过 javascript 进行转换。 这非常耗时,因为我们基本上是从代表我们当前帐户的另一个 XML 文档中手动选取数据,并将数据复制到瞬态 XML DOM 文档中。

我想做的是克隆帐户文档的相关节点(即客户信息)并将其用作转换的基础。 我不想直接使用帐户文档,因为我希望能够添加转换特定输入,而不对帐户对象进行更改。

对于通常包含 2000 多个元素的文档中通常少于 200 个元素的所需节点,使用 .cloneNode(true) 的效率如何? 目标平台是IE6,没有外部工具(即ActiveX)。

I'm building the HTML code within an XML DOM object to be used as the contents of the innerHTML of a div element using an XSL template. Traditionally we create a new XML DOM document and add the input parameters as XML Elements for the transform via javascript. This is all very time-consuming as we are basically hand picking the data from another XML document that represents our current account and copying the data into a transient XML DOM document.

What I'd like to do is clone the relevant node of the account document (i.e. customer info) and use it as the basis for the transform. I don't want to use the account document directly as I'd like to be able to add transform specific input, without making changes to the account object.

How efficient is using .cloneNode(true) for a desired node of about typically less than 200 elements from a document of typically 2000+ elements? The target platform is IE6 with no external tools (i.e. ActiveX).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

允世2024-07-14 21:18:44

CloneNode 非常高效,但这样做会消耗更多内存。

另一种需要考虑的方法是使用模板对象和处理器,将附加/更改的数据作为参数传递给处理器以及原本克隆为输入元素的元素。 不过,这种方法需要对 XSL 进行相当重要的修改。

CloneNode is pretty efficient but it will be consuming more memory doing it that way.

Another approach to consider is to use a Template object and a processor, pass your additional/changed data as parameters to the processor and the element that you would have otherwise cloned as the input element. This approach would require fairly significant mods the XSL though.

能怎样2024-07-14 21:18:44

IE 在某些事情上会失败。

例如,当您将副本添加到 DOM 时,选中的单选按钮/复选框将不会被选中。

示例:

http:// webbugtrack.blogspot.com/2008/03/bug-199-cant-clone-form-element-in-ie.html

http://webbugtrack.blogspot.com/2007/08/bug-242-setattribute-doesnt-always-work.html

要查看 IE 实际返回的内容,请尝试在其中一个页面的地址栏中用此替换 url,然后按 Enter 键。

javascript:'<xmp>'+window.document.body.outerHTML+'</xmp>';

如果您对结果感到满意,那就太棒了!,但我认为您最终会对 IE 返回的结果不满意(在 DOM 中,以及这个“字符串”值等效)。

IE will fail on certain things.

e.g. checked radio/checkboxes will not be checked when you add your copy to the DOM.

Example:

http://webbugtrack.blogspot.com/2008/03/bug-199-cant-clone-form-element-in-ie.html

http://webbugtrack.blogspot.com/2007/08/bug-242-setattribute-doesnt-always-work.html

To see what IE will actually return, try replacing the url with this in the Address Bar of one of your pages, and press enter.

javascript:'<xmp>'+window.document.body.outerHTML+'</xmp>';

If you are happy with the results, great!, but I think you'll end up less than satisfied at what IE returns (both in the DOM, and this "string" value equivelant.

初相遇2024-07-14 21:18:44

如果您不需要表单元素,cloneNode 是一个真正可靠的工具...

-- 在插入 ajax-data 时,它的效率令人难以置信...

但是,特别是 IE 一直以来都存在名称属性问题,如果您插入数据,解决这些问题都是不方便的...

-- 我不太理解您的 XSL(T) 使用,对我来说,这听起来像是使用加油站作为(不!-)方便将 1960 WV 更改为 2008 Skoda 的地方...

他们只是有一些共同的技术,尽管使用方式不同,但在某种程度上计算机化只是一个小问题,主要问题几乎在任何地方 其他方式!o]

您需要表单元素吗?-)

If you don't need form-elements, cloneNode is a real reliable tool ...

-- and in inserting ajax-data it is incredible in efficiency ...

However, as especially IE has a history of having problems with name-attributes, it is inconvenient to address any of these if you insert data ...

-- I don't really understand your XSL(T)-using, to me it sounds like using a gas-station as a (not !-) convenient place to change a 1960 WV to a 2008 Skoda ...

Userely they have some common technology, though it is not used in the same way, computerization in some way is just a minor problem, the major problems is in nearly any other way !o]

Have you got any need for form-elements ?-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文