1 /* is this stuff defined? */
2 if (!document.ELEMENT_NODE) {
3 document.ELEMENT_NODE = 1;
4 document.ATTRIBUTE_NODE = 2;
5 document.TEXT_NODE = 3;
6 document.CDATA_SECTION_NODE = 4;
7 document.ENTITY_REFERENCE_NODE = 5;
8 document.ENTITY_NODE = 6;
9 document.PROCESSING_INSTRUCTION_NODE = 7;
10 document.COMMENT_NODE = 8;
11 document.DOCUMENT_NODE = 9;
12 document.DOCUMENT_TYPE_NODE = 10;
13 document.DOCUMENT_FRAGMENT_NODE = 11;
14 document.NOTATION_NODE = 12;
17 document._importNode = function(node, allChildren) {
18 /* find the node type to import */
19 switch (node.nodeType) {
20 case document.ELEMENT_NODE:
21 /* create a new element */
22 var newNode = document.createElement(node.nodeName);
23 /* does the node have any attributes to add? */
24 if (node.attributes && node.attributes.length > 0)
25 /* add all of the attributes */
26 for (var i = 0, il = node.attributes.length; i < il;) {
27 if (node.attributes[i].nodeName == 'class') {
28 newNode.className = node.getAttribute(node.attributes[i++].nodeName);
30 newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
33 /* are we going after children too, and does the node have any? */
34 if (allChildren && node.childNodes && node.childNodes.length > 0)
35 /* recursively get all of the child nodes */
36 for (var i = 0, il = node.childNodes.length; i < il;)
37 newNode.appendChild(document._importNode(node.childNodes[i++], allChildren));
40 case document.TEXT_NODE:
41 case document.CDATA_SECTION_NODE:
42 case document.COMMENT_NODE:
43 return document.createTextNode(node.nodeValue);