Do a recursive copy of the node list. Use
          xmlDocCopyNodeList() if possible to ensure string interning.
965149
def copyNodeList(self):
        
        ret = libxml2mod.xmlCopyNodeList(self._o)
        if ret is None:raise treeError('xmlCopyNodeList() failed')
        __tmp = xmlNode(_obj=ret)
        return __tmp
365871
def tree_node_to_xml(self, parent, item):
        """"""

        tree = self.treeview
        data = self.treedata[item]
        node = data.to_xml_node()

        children = tree.get_children(item)
        for child in children:
            cnode = ET.Element('child')
            cwidget = self.tree_node_to_xml(item, child)
            cnode.append(cwidget)
            node.append(cnode)

        return node
845381
private Pair<Tree,Tree> copyHelper(Tree node,Map<String,Tree> newNamesToNodes) {
    Tree clone;
    Tree newFoot = null;
    if (node.isLeaf()) {
      if (node == foot) { // found the foot node; pass it up.
        clone = node.treeFactory().newTreeNode(node.label(),new ArrayList<Tree>(0));
        newFoot = clone;
      } else {
        clone = node.treeFactory().newLeaf(node.label().labelFactory().newLabel(node.label()));
      }
    } else {
      List<Tree> newChildren = new ArrayList<Tree>(node.children().length);
      for (Tree child : node.children()) {
        Pair<Tree,Tree> newChild = copyHelper(child,newNamesToNodes);
        newChildren.add(newChild.first());
        if (newChild.second() != null) {
          if (newFoot != null) {
            System.err.println("Error -- two feet found when copying auxiliary tree " + tree.toString() + "; using last foot found.");
          }
          newFoot = newChild.second();
        }
      }
      clone = node.treeFactory().newTreeNode(node.label().labelFactory().newLabel(node.label()),newChildren);
      if (nodesToNames.containsKey(node)) {
        newNamesToNodes.put(nodesToNames.get(node),clone);
      }
    }
    return new Pair<Tree,Tree>(clone,newFoot);
  }
276002
def LoadFromXml(self, node, handle):
		
		self.SetHandle(handle)
		if node.hasAttributes():
			# attributes = node._get_attributes()
			# attCount = attributes._get_length()
			attributes = node.attributes
			attCount = len(attributes)
			for i in range(attCount):
				attNode = attributes.item(i)
				# attr = UcsUtils.WordU(attNode._get_name())
				attr = UcsUtils.WordU(attNode.localName)
				if (UcsUtils.FindClassIdInMoMetaIgnoreCase(self.classId) != None):
					if (attr in UcsUtils.GetUcsPropertyMetaAttributeList(self.classId)):
						# self.setattr(attr, str(attNode.nodeValue))
						self.setattr(attr, str(attNode.value))
					else:
						# self.setattr(UcsUtils.WordU(attr), str(attNode.nodeValue))
						self.setattr(UcsUtils.WordU(attr), str(attNode.value))
				else:
					# self.setattr(UcsUtils.WordU(attr), str(attNode.nodeValue))
					self.setattr(UcsUtils.WordU(attr), str(attNode.value))

			if self.getattr("Rn") == None and self.getattr("Dn") != None:
				self.setattr("Rn", str(re.sub(r'^.*/', '', self.getattr("Dn"))))

		if (node.hasChildNodes()):
			# childList = node._get_childNodes()
			# childCount = childList._get_length()
			childList = node.childNodes
			childCount = len(childList)
			for i in range(childCount):
				childNode = childList.item(i)
				if (childNode.nodeType != Node.ELEMENT_NODE):
					continue

				if childNode.localName in self.propMoMeta.fieldNames:
					# .LoadFromXml(childNode, handle)
					pass
				# TODO: Need code analysis.
				# if childNode.localName in self.propMoMeta.childFieldNames:
				c = ManagedObject(UcsUtils.WordU(childNode.localName))
				self.child.append(c)
				c.LoadFromXml(childNode, handle)
533601
def copyNode(node, children=False, parent=False):
    
    if parent is not False:
        element = SubElement(
            parent,
            node.tag,
            attrib=node.attrib,
            nsmap={None: "http://www.tei-c.org/ns/1.0"}
        )
    else:
        element = Element(
            node.tag,
            attrib=node.attrib,
            nsmap={None: "http://www.tei-c.org/ns/1.0"}
        )
    if children:
        if node.text:
            element._setText(node.text)
        for child in xmliter(node):
            element.append(copy(child))
    return element
816584
def reparentChildren(self, newParent):
        
        # XXX - should this method be made more general?
        for child in self.childNodes:
            newParent.appendChild(child)
        self.childNodes = []
765979
public Node cloneNode(boolean deep) {
        try {
            if (isXMLDoc == UNKNOWN_TYPE) isXMLDoc = getDocumentType();
            if (isXMLDoc == NON_XML) {
                throw new UnsupportedOperationException(
                    "Text document cannot be cloned");
            }
            // initialize a new doc owner node
            initClonedOwnerDoc();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("Internal Error:" + e);
        }
        if (deep) {
            for (NodeImpl n = (NodeImpl) getFirstChild(); n != null; n = (NodeImpl) n
                .getNextSibling()) {
                ownerDocCloned.appendChild(n.cloneNode(ownerDocCloned, true));
            }
        }
        return ownerDocCloned;
    }
927798
function parsePlistXML (node) {
  var i, new_obj, key, val, new_arr, res, counter, type;

  if (!node)
    return null;

  if (node.nodeName === 'plist') {
    new_arr = [];
    if (isEmptyNode(node)) {
      return new_arr;
    }
    for (i=0; i < node.childNodes.length; i++) {
      if (!shouldIgnoreNode(node.childNodes[i])) {
        new_arr.push( parsePlistXML(node.childNodes[i]));
      }
    }
    return new_arr;
  } else if (node.nodeName === 'dict') {
    new_obj = {};
    key = null;
    counter = 0;
    if (isEmptyNode(node)) {
      return new_obj;
    }
    for (i=0; i < node.childNodes.length; i++) {
      if (shouldIgnoreNode(node.childNodes[i])) continue;
      if (counter % 2 === 0) {
        invariant(
          node.childNodes[i].nodeName === 'key',
          'Missing key while parsing <dict/>.'
        );
        key = parsePlistXML(node.childNodes[i]);
      } else {
        invariant(
          node.childNodes[i].nodeName !== 'key',
          'Unexpected key "'
            + parsePlistXML(node.childNodes[i])
            + '" while parsing <dict/>.'
        );
        new_obj[key] = parsePlistXML(node.childNodes[i]);
      }
      counter += 1;
    }
    if (counter % 2 === 1) {
      throw new Error('Missing value for "' + key + '" while parsing <dict/>');
    }
    return new_obj;

  } else if (node.nodeName === 'array') {
    new_arr = [];
    if (isEmptyNode(node)) {
      return new_arr;
    }
    for (i=0; i < node.childNodes.length; i++) {
      if (!shouldIgnoreNode(node.childNodes[i])) {
        res = parsePlistXML(node.childNodes[i]);
        if (null != res) new_arr.push(res);
      }
    }
    return new_arr;

  } else if (node.nodeName === '#text') {
    // TODO: what should we do with text types? (CDATA sections)

  } else if (node.nodeName === 'key') {
    if (isEmptyNode(node)) {
      return '';
    }
    return node.childNodes[0].nodeValue;
  } else if (node.nodeName === 'string') {
    res = '';
    if (isEmptyNode(node)) {
      return res;
    }
    for (i=0; i < node.childNodes.length; i++) {
      var type = node.childNodes[i].nodeType;
      if (type === TEXT_NODE || type === CDATA_NODE) {
        res += node.childNodes[i].nodeValue;
      }
    }
    return res;

  } else if (node.nodeName === 'integer') {
    invariant(
      !isEmptyNode(node),
      'Cannot parse "" as integer.'
    );
    return parseInt(node.childNodes[0].nodeValue, 10);

  } else if (node.nodeName === 'real') {
    invariant(
      !isEmptyNode(node),
      'Cannot parse "" as real.'
    );
    res = '';
    for (i=0; i < node.childNodes.length; i++) {
      if (node.childNodes[i].nodeType === TEXT_NODE) {
        res += node.childNodes[i].nodeValue;
      }
    }
    return parseFloat(res);

  } else if (node.nodeName === 'data') {
    res = '';
    if (isEmptyNode(node)) {
      return Buffer.from(res, 'base64');
    }
    for (i=0; i < node.childNodes.length; i++) {
      if (node.childNodes[i].nodeType === TEXT_NODE) {
        res += node.childNodes[i].nodeValue.replace(/\s+/g, '');
      }
    }
    return Buffer.from(res, 'base64');

  } else if (node.nodeName === 'date') {
    invariant(
      !isEmptyNode(node),
      'Cannot parse "" as Date.'
    )
    return new Date(node.childNodes[0].nodeValue);

  } else if (node.nodeName === 'true') {
    return true;

  } else if (node.nodeName === 'false') {
    return false;
  }
}
1177198
def data(self, root, preserve_root=False):
        ''''''
        # If preserve_root is False, return the root element. This is easiest
        # done by wrapping the XML in a dummy root element that will be ignored.
        if preserve_root:
            new_root = root.makeelement('dummy_root', {})
            new_root.insert(0, root)
            root = new_root

        # If no children, just return the text
        children = [node for node in root if isinstance(node.tag, basestring)]
        if len(children) == 0:
            return self._fromstring(root.text)

        # Element names become object properties
        count = Counter(child.tag for child in children)
        result = self.dict()
        for child in children:
            if count[child.tag] == 1:
                result[child.tag] = self.data(child)
            else:
                result.setdefault(child.tag, self.list()).append(self.data(child))

        return result
918850
function(recursive, callback) {
		var i, l, node,
			dict = {},
			self = this;

		$.each(NODE_ATTRS, function(i, a){
			if(self[a] || self[a] === false){
				dict[a] = self[a];
			}
		});
		if(!$.isEmptyObject(this.data)){
			dict.data = $.extend({}, this.data);
			if($.isEmptyObject(dict.data)){
				delete dict.data;
			}
		}
		if( callback ){
			callback(dict);
		}
		if( recursive ) {
			if(this.hasChildren()){
				dict.children = [];
				for(i=0, l=this.children.length; i<l; i++ ){
					node = this.children[i];
					if( !node.isStatusNode() ){
						dict.children.push(node.toDict(true, callback));
					}
				}
			}else{
//                dict.children = null;
			}
		}
		return dict;
	}
949736
def copyNode(self, extended):
        
        ret = libxml2mod.xmlCopyNode(self._o, extended)
        if ret is None:raise treeError('xmlCopyNode() failed')
        __tmp = xmlNode(_obj=ret)
        return __tmp
322587
def copy(self):
        
        return LabeledTree(
            udepth = self.udepth,
            depth = self.depth,
            text = self.text,
            label = self.label,
            children = self.children.copy() if self.children != None else [],
            parent = self.parent)
697666
public static <T, R> TreeNode<R> copy(TreeDef<T> treeDef, T root, Function<? super T, ? extends R> mapper) {
		List<T> children = treeDef.childrenOf(root);
		R mapped = mapper.apply(root);
		TreeNode<R> copyRoot = new TreeNode<>(null, mapped, children.size());
		copyRecurse(copyRoot, treeDef, root, children, mapper);
		return copyRoot;
	}
674815
def copytree(src, dst, overwrite=False, ignore_list=None, debug=False):
    
    if ignore_list is None:
        ignore_list = []
    if debug:
        print('copytree {} to {}'.format(src, dst))
    for child in Path(src).iterdir():
        if debug:
            print("  on file {}".format(child))
        if child.name not in ignore_list:
            if child.is_dir():
                new_dir = Path(dst) / child.relative_to(src)
                new_dir.mkdir(exist_ok=True)
                # call recursively
                copytree(child, new_dir, overwrite, ignore_list, debug)
            elif child.is_file():
                new_file = new_dir = Path(dst) / child.relative_to(src)
                if debug:
                    print("    to file {}".format(new_file))
                if new_file.exists():
                    if overwrite:
                        new_file.unlink()
                        shutil.copy2(child, new_file)
                else:
                    shutil.copy2(child, new_file)
        else:
            if debug:
                print("  Skipping copy of {}".format(child))
516933
def cloneNode(self, deep: bool=False) -> AbstractNode:
        
        if deep:
            return self._clone_node_deep()
        return self._clone_node()
1158824
public static NodeList<Element> copyNodeList(NodeList<Element> oldNodes,
      NodeList<Element> newNodes, boolean create) {
    NodeList<Element> ret = oldNodes == null || create ? JsNodeArray.create()
        : oldNodes;
    JsCache idlist = JsCache.create();
    for (int i = 0; oldNodes != null && i < oldNodes.getLength(); i++) {
      Element e = oldNodes.getItem(i);
      idlist.put(e.hashCode(), 1);
      if (create) {
        ret.<JsNodeArray> cast().addNode(e, i);
      }
    }
    for (int i = 0, l = newNodes.getLength(), j = ret.getLength(); i < l; i++) {
      Element e = newNodes.getItem(i);
      if (!idlist.exists(e.hashCode())) {
        ret.<JsNodeArray> cast().addNode(newNodes.getItem(i), j++);
      }
    }
    return ret;
  }
195733
def newReference(self, name):
        
        ret = libxml2mod.xmlNewReference(self._o, name)
        if ret is None:raise treeError('xmlNewReference() failed')
        __tmp = xmlNode(_obj=ret)
        return __tmp