def load_elem(element, ignore=None): """Load the given XML element as a `dict`, skipping any child elements listed in the given `ignore` argument.""" result = data.load_attrs(element) or {} result['kind'] = element.tag for child in list(element): if ignore and child.tag in ignore: continue name, value = data.load_elem(child) result[name] = value return result
def load_layout(element): """Load layout data from the given XML element.""" # Load everything except for the row & fieldset elements result = load_elem(element, ignore=["row", "fieldset"]) # Load the form fieldset as a simple array of elements if element.tag == "form": fieldset = element.find("fieldset") result['fieldset'] = load_elem(fieldset, ignore="input") result['fieldset']['inputs'] = load_list(fieldset, "input", load_input) # Collect all row elements into an array of row objects rows = [] for item in element.findall("row"): row = data.load_attrs(item) or {} row['panels'] = [load_panel(panel) for panel in list(item)] rows.append(row) result['rows'] = rows return result