Bulids the tree with all the fields converted to Elements
171271
def build_tree(self):
        
        if self.built:
            return
        self.doc_root = self.root.element()
        for key in self.sorted_fields():
            if key not in self._fields:
                continue
            field = self._fields[key]
            if field != self.root:
                if isinstance(field, XmlModel):
                    field.build_tree()
                    if (self.drop_empty and field.drop_empty
                        and len(field.doc_root) == 0):
                        continue
                    self.doc_root.append(field.doc_root)
                elif isinstance(field, list):
                    # we just allow XmlFields and XmlModels
                    # Also xml as str for memory management
                    for item in field:
                        if isinstance(item, XmlField):
                            ele = item.element()
                            if self.drop_empty and len(ele) == 0:
                                continue
                            self.doc_root.append(ele)
                        elif isinstance(item, XmlModel):
                            item.build_tree()
                            if self.drop_empty and len(item.doc_root) == 0:
                                continue
                            self.doc_root.append(item.doc_root)
                        elif isinstance(item, (six.text_type, six.string_types)):
                            ele = etree.fromstring(clean_xml(item))
                            self.doc_root.append(ele)
                        item = None
                elif (field.parent or self.root.name) == self.root.name:
                    ele = field.element()
                    if self.drop_empty and len(ele) == 0 and not ele.text:
                        continue
                    ele = field.element(parent=self.doc_root)
                else:
                    nodes = [n for n in self.doc_root.iterdescendants(
                                            tag=field.parent)]
                    if nodes:
                        ele = field.element()
                        if (self.drop_empty and len(ele) == 0 and not ele.text):
                            continue
                        ele = field.element(parent=nodes[0])
                    #else:
                    #    raise RuntimeError("No parent found!")
        self.built = True
650676
function toArrayTree (array, options) {
  var opts = baseExports.assign({}, setupDefaults.treeOptions, options)
  var optStrict = opts.strict
  var optKey = opts.key
  var optParentKey = opts.parentKey
  var optChildren = opts.children
  var optSortKey = opts.sortKey
  var optReverse = opts.reverse
  var optData = opts.data
  var result = []
  var treeMap = {}
  var idList, id, treeData, parentId

  if (optSortKey) {
    array = arraySort(baseExports.clone(array), optSortKey)
    if (optReverse) {
      array = array.reverse()
    }
  }

  idList = arrayMap(array, function (item) {
    return item[optKey]
  })

  baseExports.each(array, function (item) {
    id = item[optKey]

    if (optData) {
      treeData = {}
      treeData[optData] = item
    } else {
      treeData = item
    }

    parentId = item[optParentKey]
    treeMap[id] = treeMap[id] || []
    treeMap[parentId] = treeMap[parentId] || []
    treeMap[parentId].push(treeData)
    treeData[optKey] = id
    treeData[optParentKey] = parentId
    treeData[optChildren] = treeMap[id]

    if (!optStrict || (optStrict && !parentId)) {
      if (!baseExports.includes(idList, parentId)) {
        result.push(treeData)
      }
    }
  })

  if (optStrict) {
    strictTree(array, optChildren)
  }

  return result
}
1284810
def as_tree(self):
        ""
        if self._nodes is None:
            return [self]
        ret = [self]
        for node in self._nodes:
            ret.append(node.as_tree())
        return ret
211940
function(result) {
    var oResult = {},
        schema = this.responseSchema;
        
    try {
        // Loop through each data field in each result using the schema
        for(var m = schema.fields.length-1; m >= 0 ; m--) {
            var field = schema.fields[m];
            var key = (lang.isValue(field.key)) ? field.key : field;
            var data = null;

            if(this.useXPath) {
                data = YAHOO.util.DataSource._getLocationValue(field, result);
            }
            else {
                // Values may be held in an attribute...
                var xmlAttr = result.attributes.getNamedItem(key);
                if(xmlAttr) {
                    data = xmlAttr.value;
                }
                // ...or in a node
                else {
                    var xmlNode = result.getElementsByTagName(key);
                    if(xmlNode && xmlNode.item(0)) {
                        var item = xmlNode.item(0);
                        // For IE, then DOM...
                        data = (item) ? ((item.text) ? item.text : (item.textContent) ? item.textContent : null) : null;
                        // ...then fallback, but check for multiple child nodes
                        if(!data) {
                            var datapieces = [];
                            for(var j=0, len=item.childNodes.length; j<len; j++) {
                                if(item.childNodes[j].nodeValue) {
                                    datapieces[datapieces.length] = item.childNodes[j].nodeValue;
                                }
                            }
                            if(datapieces.length > 0) {
                                data = datapieces.join("");
                            }
                        }
                    }
                }
            }
            
            
            // Safety net
            if(data === null) {
                   data = "";
            }
            // Backward compatibility
            if(!field.parser && field.converter) {
                field.parser = field.converter;
                YAHOO.log("The field property converter has been deprecated" +
                        " in favor of parser", "warn", this.toString());
            }
            var parser = (typeof field.parser === 'function') ?
                field.parser :
                DS.Parser[field.parser+''];
            if(parser) {
                data = parser.call(this, data);
            }
            // Safety measure
            if(data === undefined) {
                data = null;
            }
            oResult[key] = data;
        }
    }
    catch(e) {
        YAHOO.log("Error while parsing XML result: " + e.message);
    }

    return oResult;
}
241595
def to_etree(self):
        
        layers_attrib_val = ' '.join('//@layers.{}'.format(layer_id)
                                     for layer_id in self.layers)

        attribs = {
            '{{{pre}}}type'.format(pre=NAMESPACES['xsi']): self.xsi_type,
            'layers': layers_attrib_val}

        E = ElementMaker()
        node = E('nodes', attribs)
        label_elements = (label.to_etree() for label in self.labels)
        node.extend(label_elements)
        return node
157486
function parseChildrenProperties( root, libs, com, indent ) {
  if (!Array.isArray( root.children )) {
    root.children = [ ];
  }
  root.children.forEach( function( child ) {
    debugger;
    if ( child.type != libs.Tree.TAG ) {
      return;
    }
    libs.compileChildren( child );

    if ( typeof child.attribs === 'undefined' ) {
      child.attribs = {};
    }
    if ( child.attribs.json === null ) {
      parsePropertyJSON( child, libs, com );
    }
    else {
      // By default, this is a list.
      parsePropertyList( child, libs, com, indent + "  " );
    }
  });
}
1024387
def _from_fields(self, fields):
        '''
        

        '''
        return _np.dtype(self.dtype()).type(next(fields))
1309540
static  function toTree($list,$parent_field = 'parent_id',$id_field='id',$children_field='children') {
        $map = self::groupBy($list);
        $data=[];
        foreach ($list as $item) {
            $item->text=$item->name;
            if(is_object($item)){
                if(!$item->$parent_field){
                    $item->$children_field=$map[$item->$id_field];
                    $data[]=$item;
                }
            }
        }
        return $data;
    }
821957
function buildElementsTree(contexts) {

	contexts = contexts || [document];

	var queriesArray = Object.keys(queries).map(function(key) {
		return queries[key];
	});

	var selector = queriesArray.map(function(query) {
		return query._selector;
	}).join(',');

	var elements = [];
	contexts.forEach(function(context) {
		for (var node = context.parentNode; node; node = node.parentNode) {
			// Skip nested contexts
			if (contexts.indexOf(node) !== -1) {
				return;
			}
		}
		if (context !== document && elementMatchesSelector(context, selector)) {
			elements.push(context);
		}
		elements.push.apply(elements, arrayFrom(context.querySelectorAll(selector)));
	});

	var tree = [];
	var treeCache = createCacheMap();

	elements.forEach(function(element) {

		if (element === documentElement) {
			return;
		}

		var treeNode = {
			_element: element,
			_children: [],
			_queries: [],
			_changes: [],
			_done: false,
		};

		var children = tree;
		for (var node = element.parentNode; node; node = node.parentNode) {
			if (treeCache.get(node)) {
				children = treeCache.get(node)._children;
				break;
			}
		}

		treeCache.set(element, treeNode);

		children.push(treeNode);

		queriesArray.forEach(function(query) {
			if (elementMatchesSelector(element, query._selector)) {
				treeNode._queries.push(query);
			}
		});

	});

	return tree;

}
1359063
function () {
			var tree,
				series = this,
				i = 0,
				parentList = [],
				allIds = [],
				key,
				insertItem = function (key) {
					each(parentList[key], function (item) {
						parentList[""].push(item);
					});
				},
				getNodeTree = function (id, i, level, list, points, parent) {
					var children = [],
						sortedChildren = [],
						childrenTotal = 0,
						val,
						point = points[i],
						nodeTree,
						node,
						insertNode,
						name;
					insertNode = function () {
						var i = 0,
							inserted = false;
						if (sortedChildren.length !== 0) {
							each(sortedChildren, function (child) {
								if (node.val > child.val && !inserted) {
									sortedChildren.splice(i, 0, node);
									inserted = true;
								}
								i = i + 1;					
							});
						} 
						if (!inserted) {
							sortedChildren.push(node);
						}
					};

					// Actions
					if (point) {
						name = point.name || "";
					}
					if (list[id] !== undefined) {
						each(list[id], function (i) {
							node = getNodeTree(points[i].id, i, (level + 1), list, points, id);
							childrenTotal += node.val;
							insertNode();
							children.push(node);
						});
					}
					val = pick((points[i] && points[i].value), childrenTotal, 0);
					nodeTree = {
						id: id,
						i: i,
						children: sortedChildren,
						childrenTotal: childrenTotal,
						val: val,
						level: level,
						parent: parent,
						name: name
					};
					series.nodeMap[nodeTree.id] = nodeTree;
					return nodeTree;
				};
			// Actions
			// Map children to index
			each(this.points, function (point) {
				var parent = "";
				allIds.push(point.id);
				if (point.parent !== undefined) {
					parent = point.parent;
				}
				if (parentList[parent] === undefined) {
					parentList[parent] = [];
				}
				parentList[parent].push(i);
				i = i + 1;
			});
			/* 
			*  Quality check:
			*  - If parent does not exist, then set parent to tree root
			*  - Add node id to parents children list
			*/  
			for (key in parentList) {
				if (parentList.hasOwnProperty(key)) {
					if (key !== "") {
						if (HighchartsAdapter.inArray(key, allIds) === -1) {
							insertItem(key);
							delete parentList[key];
						}
					}
				}
			}
			tree = getNodeTree("", -1, 0, parentList, this.points, null);
			return tree;
		}
599181
function element(node, options = {}) {
  const { namespace } = options;
  const { tagName, properties, children = [] } = node;
  const el = typeof namespace !== 'undefined'
    ? document.createElementNS(namespace, tagName)
    : document.createElement(tagName);

  // Add HTML attributes
  const props = Object.keys(properties);
  const { length } = props;
  for (let i = 0; i < length; i += 1) {
    const key = props[i];
    const {
      attribute,
      property,
      mustUseAttribute,
      mustUseProperty,
      boolean,
      booleanish,
      overloadedBoolean,
      // number,
      // defined,
      commaSeparated,
      spaceSeparated,
      // commaOrSpaceSeparated,
    } = info.find(info.html, key) || {
      attribute: key,
      property: key,
    };

    let value = properties[key];
    if (Array.isArray(value)) {
      if (commaSeparated) {
        value = value.join(', ');
      } else if (spaceSeparated) {
        value = value.join(' ');
      } else {
        value = value.join(' ');
      }
    }

    try {
      if (mustUseProperty) {
        el[property] = value;
      }
      if (boolean || (overloadedBoolean && typeof value === 'boolean')) {
        if (value) {
          el.setAttribute(attribute, '');
        } else {
          el.removeAttribute(attribute);
        }
      } else if (booleanish) {
        el.setAttribute(attribute, value);
      } else if (value === true) {
        el.setAttribute(attribute, '');
      } else if (value || value === 0 || value === '') {
        el.setAttribute(attribute, value);
      }
    } catch (e) {
      if (!mustUseAttribute && property) {
        el[property] = value;
      }
      // Otherwise silently ignore
    }
  }

  // Transform children
  const { length: childrenLength } = children;
  for (let i = 0; i < childrenLength; i += 1) {
    const childEl = transform(children[i], options);
    if (childEl) {
      el.appendChild(childEl);
    }
  }

  return el;
}
988120
private void processProps() {
    ElementFilter
        .fieldsIn(component.getEnclosedElements())
        .stream()
        .filter(field -> hasAnnotation(field, Prop.class))
        .forEach(field -> {
          String propName = field.getSimpleName().toString();
          Prop prop = field.getAnnotation(Prop.class);

          collectionFieldsValidator.validateComponentPropField(field);

          fieldsWithNameExposed.add(new ExposedField(propName, field.asType()));

          optionsBuilder.addStatement(
              "options.addJavaProp($S, $T.getFieldName(this, () -> this.$L = $L), $L, $S)",
              propName,
              VueGWTTools.class,
              propName,
              getFieldMarkingValueForType(field.asType()),
              prop.required(),
              prop.checkType() ? getNativeNameForJavaType(field.asType()) : null
          );
        });
  }
1091879
def leaf_keyvalue node
    h = {}
    node.children.each do |child|
      next unless child.element?
      h[child.name] = child.content
    end
    [h['key'], h['value']]
  end
815980
def to_element(self, root_name=None):
        """"""
        if not root_name:
            root_name = self.nodename
        elem = ElementTreeBuilder.Element(root_name)
        for attrname in self.serializable_attributes():
            # Only use values that have been loaded into the internal
            # __dict__. For retrieved objects we look into the XML response at
            # access time, so the internal __dict__ contains only the elements
            # that have been set on the client side.
            try:
                value = self.__dict__[attrname]
            except KeyError:
                continue

            if attrname in self.xml_attribute_attributes:
                elem.attrib[attrname] = six.text_type(value)
            else:
                sub_elem = self.element_for_value(attrname, value)
                elem.append(sub_elem)

        return elem
893094
function(parent, field, options) {  
  options = options || {};
  // Unique id for this node's generated method
  this.id = utils.generateId();
  // Link to parent node
  this.parent = parent;
  // The field related to this node
  this.field = field;
  // Perform type check or not on generation
  this.typeCheck = typeof options.typeCheck == 'boolean' ? options.typeCheck : false;
  // Validation language
  this.validation = options.validation ? options.validation : null;
  // Any options
  this.options = options;
  // All children attached to this node
  this.children = [];
  // Just some metadata
  this.type = 'enum';
}
323804
def populate_tree(self, master, parent, element,from_file=False):
        """"""

        data = WidgetDescr(None, None)
        data.from_xml_node(element)
        cname = data.get_class()
        uniqueid = self.get_unique_id(cname, data.get_id())
        data.set_property('id', uniqueid)

        if cname in builder.CLASS_MAP:
            pwidget = self._insert_item(master, data,from_file=from_file)
            xpath = "./child"
            children = element.findall(xpath)
            for child in children:
                child_object = child.find('./object')
                cwidget = self.populate_tree(pwidget, child, child_object,from_file=from_file)

            return pwidget
        else:
            raise Exception('Class "{0}" not mapped'.format(cname))
768308
def node_field_ast(field)
      f_ast = field_ast(field)
      return nil if f_ast.nil?
      type = field.type.unwrap
      selections = f_ast.selections.dup

      if type.kind.object?
        selections << field_ast(type.get_field('id'))
      else
        possible_node_types(type).each do |if_type|
          selections << inline_fragment_ast(if_type, with_children: false)
        end
      end

      selections.compact!

      if f_ast.respond_to?(:merge) # GraphQL-Ruby 1.9+
        f_ast = f_ast.merge(selections: selections)
      else
        f_ast.selections = selections
      end
      f_ast
    end