function copy_dom to from var children from from childNodes undefined

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
function copy_dom(to,from){
var children=from?from.childNodes:undefined;
if(children)if(children.length)for(a=0;a<children.length;a++)if(children[a]){//alert("!!!")
if(children[a].nodeType==Node.ELEMENT_NODE){
var attrs=children[a].attributes;
var rt=to.ownerDocument.createElementNS(children[a].namespaceURI,children[a].tagName);
if(attrs)for(b=0;b<attrs.length;b++)
rt.setAttributeNS(attrs.item(b).namespaceURI,attrs.item(b).name,attrs.item(b).value);
copy_dom(rt,children[a]);
to.appendChild(rt);
}
if(children[a].nodeType==Node.TEXT_NODE)alert("text");
if(children[a].nodeType==Node.CDATA_SECTION_NODE )alert("cdata");
if(children[a].nodeType==Node.COMMENT_NODE )alert("comment");
}
return to;
}