Helper function to recursively populates a Bunch from an XML tree.
    Returns leaf XML elements as a simple value, branch elements are returned
    as Bunches containing their subelements as value or recursively generated
    Bunch members.
485750
def _populate_bunch_with_element(element):
    
    if 'value' in element.attrib:
        return element.get('value')
    current_bunch = Bunch()

    if element.get('id'):
        current_bunch['nextra_element_id'] = element.get('id')
    for subelement in element.getchildren():
        current_bunch[subelement.tag] = _populate_bunch_with_element(
            subelement)
    return current_bunch
513960
private String genXML(Set nodes) throws IOException {
        Iterator it = nodes.iterator();
        StringBuffer buf = new StringBuffer(1024);
        buf.append(StateHelper.XML_DOC_START);
        buf.append(getSynchInterval());
        buf.append(StateHelper.XML_DOC_START_END);
        while (it.hasNext()) {
            Node n = (Node) it.next();
            buf.append(StateHelper.XML_NODE_TAG_START);
            buf.append(StateHelper.encodeMACAddress(n.getNodeIdentifier()));
            buf.append(StateHelper.XML_NODE_TAG_AFTER_ID);
            buf.append(n.getClockSequence());
            buf.append(StateHelper.XML_NODE_TAG_AFTER_CSEQ);
            buf.append(n.getLastTimestamp());
            buf.append(StateHelper.XML_NODE_TAG_END);
        }
        buf.append(StateHelper.XML_DOC_END);
        return buf.toString();
    }
652828
def populate(self, node_generator):
        
        for data in node_generator:
            hashed = hash_byte_array(data)
            self.tree.add_leaf(hashed)
730286
def get_element_tree(parent_to_parse):
    

    if isinstance(parent_to_parse, ElementTree):
        return parent_to_parse

    element = get_element(parent_to_parse)

    return ElementTree() if element is None else ElementTree(element)
727780
def from_etree(
    el, node=None, node_cls=None,
    tagsub=functools.partial(re.sub, r'\{.+?\}', ''),
    Node=Node):
    '''
    '''
    node_cls = node_cls or Node
    if node is None:
        node = node_cls()
    tag = tagsub(el.tag)
    attrib = dict((tagsub(k), v) for (k, v) in el.attrib.items())
    node.update(attrib, tag=tag)

    if el.text:
        node['text'] = el.text
    for child in el:
        child = from_etree(child, node_cls=node_cls)
        node.append(child)
    if el.tail:
        node['tail'] = el.tail
    return node
515036
public XMLElementList getChildren() {
		if (children != null) {
			return children;
		}
		
		NodeList list = dom.getChildNodes();
		children = new XMLElementList();
		
		for (int i=0;i<list.getLength();i++) {
			if (list.item(i) instanceof Element) {
				children.add(new XMLElement((Element) list.item(i)));
			}
		}
		
		return children;
	}
1348031
function _addToTree(tree, branchToken, leafToken) {
  /* eslint-disable max-len, no-param-reassign */
  const leafValue = Utils.merge(tree[branchToken].fields[leafToken] || {}, _parseLeafToken(leafToken));
  tree[branchToken].fields[leafToken] = leafValue;
  /* eslint-enable max-len, no-param-reassign */

  return tree;
}
867325
def tree_to_xml(self):
        """"""

        # Need to remove filter or hidden items will not be saved.
        self.filter_remove(remember=True)

        tree = self.treeview
        root = ET.Element('interface')
        items = tree.get_children()
        for item in items:
            node = self.tree_node_to_xml('', item)
            root.append(node)

        # restore filter
        self.filter_restore()

        return ET.ElementTree(root)
1123481
def get_textnode_subtrees(html_tree,
                          xpath_to_text=TEXT_FINDER_XPATH):
    

    try:
        xpath_finder = html_tree.getroot().getroottree().getpath
    except(AttributeError):
        xpath_finder = html_tree.getroottree().getpath

    nodes_with_text = html_tree.xpath(xpath_to_text)

    # Within the TextNodeSubTree construction, the ABSL is calculated
    # refer to eatiht_trees.py
    parentpaths_textnodes = [TextNodeSubTree(n, xpath_finder(n),
                                             n.xpath('.//text()'))
                             for n in nodes_with_text]

    if len(parentpaths_textnodes) is 0:
        raise Exception("No text nodes satisfied the xpath:\n\n" +
                        xpath_to_text + "\n\nThis can be due to user's" +
                        " custom xpath, min_str_length value, or both")

    return parentpaths_textnodes
1081338
private static TreeElement recursiveFindSelected(TreeElement elem)
    {
        assert(elem != null);

        if (elem.isSelected())
            return elem;

        TreeElement children[] = elem.getChildren();
        assert(children != null);
        for (int i = 0; i < children.length; i++) {
            TreeElement e = recursiveFindSelected(children[i]);
            if (e != null)
                return e;
        }
        return null;
    }
580026
def to_xml(self, xmllint=False):
        
        root = self._tree.getroot()
        ret = ET.tostring(ET.ElementTree(root), pretty_print=True)
        if xmllint:
            ret = xmllint_format(ret)
        return ret
588524
def nodePop(ctxt):
    
    if ctxt is None: ctxt__o = None
    else: ctxt__o = ctxt._o
    ret = libxml2mod.nodePop(ctxt__o)
    if ret is None:raise treeError('nodePop() failed')
    return xmlNode(_obj=ret)
147135
def get_child_values(parent, names):
        
        vals = []
        for name in names:
            if parent.HasElement(name):
                vals.append(XmlHelper.as_value(parent.GetElement(name)))
            else:
                vals.append(np.nan)
        return vals
1255539
def build_subtree_strut(self, result, *args, **kwargs):
        
        items = list(result)
        root_elem = {"node": None, "children": OrderedDict()}
        if len(items) == 0:
            return root_elem
        for _, node in enumerate(items):
            new_elem = {"node": node.Resource, "children": OrderedDict()}
            path = list(map(int, node.path.split("/")))
            parent_node = root_elem
            normalized_path = path[:-1]
            if normalized_path:
                for path_part in normalized_path:
                    parent_node = parent_node["children"][path_part]
            parent_node["children"][new_elem["node"].resource_id] = new_elem
        return root_elem
267546
def branch(self):
        
        branch = [self]
        for c in self.children:
            branch += c.branch()
        return branch
889890
def collect_fields(node):
    
    fields = set()
    for leaf in node:
        if leaf.get('kind', None) == "Field":
            fields.add(leaf["name"]["value"])

        if leaf.get("selection_set", None):
            fields = fields.union(collect_fields(leaf["selection_set"]["selections"]))

    return fields
1056542
def get_tree(cls, parent=None):
        
        if parent:
            depth = parent.get_depth() + 1
            results = [parent]
        else:
            depth = 1
            results = []
        cls._get_tree_recursively(results, parent, depth)
        return results