def defaultHandler(elem, resolver, context): """Handle normal text and any XML that does not have a specific handler""" # Name preference order is: "key" attribute of tag (for lists) > "name" attribute of tag > "name" child of tag > tag childReorg(elem, context.path) nameChild = elem.find("name") if nameChild is not None: name = nameChild.text else: name = elem.tag name = elem.attrib.get("name", elem.tag) name = elem.attrib.get("listkey", name) name = formatTag( name) # Get rid of the namespace indicator b/c that's ugly # ns = fore = None #more = elem.find("more") #if more is None: # more = elem.find("{%s}more" % SAFplusNamespace) #if more is not None: if elem._children: # it will either have child nodes or a "more" child node if it has children fore = NodeColor else: fore = LeafColor if elem.text: top = name + ":" + elem.text else: top = name w = xmlterm.FancyTextChunked(resolver.parentWin, (" " * resolver.depth) + top, chunkSize=2048, fore=fore) resolver.add(w) resolver.depth += 1 context.path.append(elem.tag) for child in elem: resolver.resolve(child, context) if child.tail and child.tail.strip(): w = xmlterm.FancyTextChunked(resolver.parentWin, (" " * resolver.depth) + child.tail, chunkSize=2048) resolver.add(w) del context.path[-1] resolver.depth -= 1
def childrenOnlyHandler(elem, resolver, context): """Make this XML node invisible -- skip down to the children""" childReorg(elem, context.path) for child in elem: resolver.resolve(child, context) if child.tail and child.tail.strip(): w = xmlterm.FancyTextChunked(resolver.parentWin, (" " * resolver.depth) + child.tail, chunkSize=2048) resolver.add(w)
def topHandler(elem, resolver, context): """Make this XML node invisible -- skip down to the children""" childReorg(elem, context.path) for child in elem: fullpath = child.attrib.get("path", None) if fullpath: # print out the full path with a : if it is placed into the child's attribute list. This only happens for top level nodes so the user can see where they were found resolver.add( xmlterm.FancyText(resolver.parentWin, fullpath + ":", fore=FullPathColor)) resolver.depth += 1 resolver.resolve(child, context) if fullpath: resolver.depth -= 1 if child.tail and child.tail.strip(): w = xmlterm.FancyTextChunked(resolver.parentWin, (" " * resolver.depth) + child.tail, chunkSize=2048) resolver.add(w)