1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
function clone(elem){
if(elem.nodeName == "#text")
return elem;
c = document.createElement(elem.nodeName);
if(elem.hasAttributes()){
for(var i=0;i<elem.attributes.length;i++){
var curr = elem.attributes[i];
c.setAttribute(curr.name,curr.value);
}
}
return c;
}
function addChild(par,enf){
if(enf.childNodes.length > 0){
var tmpe = new Array();
while(enf.childNodes.length > 0){
var elem = enf.removeChild(enf.firstChild);
tmpe.push(elem);
}
if(enf.parentNode){
var epar = enf.parentNode;
var el = epar.removeChild(enf);
par.appendChild(clone(el));
}
else
par.appendChild(clone(enf));
var cmpt=0;
while(tmpe.length>0){
this.addChild(par.lastChild,tmpe.shift());
cmpt++;
}
}
else{
par.appendChild(clone(enf));
}
} |