Format the root node for use as the body node.
481177
def formatBodyNode(root,path):
    ''''''
    body        = root
    body.name   = "body"
    body.weight = calcFnWeight(body)
    body.path   = path
    body.pclass = None
    return body
1230087
def tostring(self, root=None, doctype=None, pretty_print=True):
        """"""
        if root is None:
            root = self.root
        return etree.tounicode(
            root, doctype=doctype or self.info.doctype, pretty_print=pretty_print
        )
1307843
function simplifyDOM(root, atEnd) {
    var doc = root.ownerDocument;
    var result = [];
    var leaving = true;

    function simplifyNode(node, top) {
      if (node.nodeType == 3) {
        var text = node.nodeValue = fixSpaces(node.nodeValue.replace(/[\r\u200b]/g, "").replace(/\n/g, " "));
        if (text.length) leaving = false;
        result.push(node);
      }
      else if (isBR(node) && node.childNodes.length == 0) {
        leaving = true;
        result.push(node);
      }
      else {
        forEach(node.childNodes, simplifyNode);
        if (!leaving && newlineElements.hasOwnProperty(node.nodeName.toUpperCase())) {
          leaving = true;
          if (!atEnd || !top)
            result.push(doc.createElement("BR"));
        }
      }
    }

    simplifyNode(root, true);
    return result;
  }
1211249
def _rename_node(self, name, new_name):
        
        # Update parent
        if not self.is_root(name):
            parent = self._db[name]["parent"]
            self._db[parent]["children"].remove(name)
            self._db[parent]["children"] = sorted(
                self._db[parent]["children"] + [new_name]
            )
        # Update children
        iobj = self._get_subtree(name) if name != self.root_name else self.nodes
        for key in iobj:
            new_key = key.replace(name, new_name, 1)
            new_parent = (
                self._db[key]["parent"]
                if key == name
                else self._db[key]["parent"].replace(name, new_name, 1)
            )
            self._db[new_key] = {
                "parent": new_parent,
                "children": [
                    child.replace(name, new_name, 1)
                    for child in self._db[key]["children"]
                ],
                "data": copy.deepcopy(self._db[key]["data"]),
            }
            del self._db[key]
        if name == self.root_name:
            self._root = new_name
            self._root_hierarchy_length = len(
                self.root_name.split(self._node_separator)
            )
663898
def format_file_node(import_graph, node, indent):
    """"""
    f = import_graph.provenance[node]
    if isinstance(f, resolve.Direct):
        out = '+ ' + f.short_path
    elif isinstance(f, resolve.Local):
        out = '  ' + f.short_path
    elif isinstance(f, resolve.System):
        out = ':: ' + f.short_path
    elif isinstance(f, resolve.Builtin):
        out = '(%s)' % f.module_name
    else:
        out = '%r' % node
    return '  '*indent + out
925139
def nodeDumpOutput(self, doc, cur, level, format, encoding):
        
        if doc is None: doc__o = None
        else: doc__o = doc._o
        if cur is None: cur__o = None
        else: cur__o = cur._o
        libxml2mod.xmlNodeDumpOutput(self._o, doc__o, cur__o, level, format, encoding)
503193
def node_to_elem(root):
    
    def generate_elem(append, node, level):
        var = "e" + str(level)
        arg = repr(node.tag)
        if node.attrib:
            arg += ", **%r" % node.attrib
        if level == 1:
            append("e1 = Element(%s)" % arg)
        else:
            append("%s = SubElement(e%d, %s)" % (var, level - 1, arg))
        if not node.nodes:
            append("%s.text = %r" % (var, node.text))
        for x in node:
            generate_elem(append, x, level + 1)
    # generate code to create a tree
    output = []
    generate_elem(output.append, root, 1)  # print "\n".join(output)
    namespace = {"Element": ElementTree.Element,
                 "SubElement": ElementTree.SubElement}
    exec("\n".join(output), globals(), namespace)
    return namespace["e1"]
582139
def parse_root(raw):
    ""
    if sys.version < '3':
        fp = StringIO(raw)
    else:
        fp = BytesIO(raw.encode('UTF-8'))
    for event, element in etree.iterparse(fp, events=('start',)):
        return (element.tag, element.attrib)
821082
private String formatNode(PatriciaTrie.PatriciaNode<V> node, int bit, KeyMapper<String> keyMapper,
                    boolean formatBitString) {
        if (node.getBit() <= bit) {
            return "";
        } else {
            StringBuffer buffer = new StringBuffer();
            buffer.append("\"");
            buffer.append(getNodeId(node));
            buffer.append("\"");
            buffer.append(" [ ");
            buffer.append("label=");
            buffer.append(formatNodeLabel(node, keyMapper, formatBitString));
            buffer.append(" ]");
            buffer.append("\n");

            buffer.append(formatPointer(node, node.getLeft(), "l", "sw"));
            buffer.append(formatPointer(node, node.getRight(), "r", "se"));

            buffer.append(formatNode(node.getLeft(), node.getBit(), keyMapper, formatBitString));
            buffer.append(formatNode(node.getRight(), node.getBit(), keyMapper, formatBitString));

            return buffer.toString();
        }
    }
177622
function root(node, options = {}) {
  const {
    fragment,
    namespace: optionsNamespace,
  } = options;
  const { children = [] } = node;
  const { length: childrenLength } = children;

  let namespace = optionsNamespace;
  let rootIsDocument = childrenLength === 0;

  for (let i = 0; i < childrenLength; i += 1) {
    const {
      tagName,
      properties: {
        xmlns,
      } = {},
    } = children[i];
    if (tagName === 'html') {
      // If we have a root HTML node, we don't need to render as a fragment
      rootIsDocument = true;
      // Take namespace of first child
      if (typeof optionsNamespace === 'undefined') {
        if (xmlns) {
          namespace = xmlns;
        } else if (children[0].tagName === 'html') {
          namespace = 'http://www.w3.org/1999/xhtml';
        }
      }
    }
  }

  // The root node will be a Document, DocumentFragment, or HTMLElement
  let el;
  if (rootIsDocument) {
    el = document.implementation.createDocument(namespace, '', null);
  } else if (fragment) {
    el = document.createDocumentFragment();
  } else {
    el = document.createElement('html');
  }

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

  return el;
}
438057
def RootNode(self):
        """"""
        tree = self.loader.get_root( self.viewType )
        adapter = self.loader.get_adapter( self.viewType )
        rows = self.loader.get_rows( self.viewType )
        
        adapter.SetPercentage(self.percentageView, adapter.value( tree ))
        
        return adapter, tree, rows
105760
def describe_root(record, root, indent=0, suppress_values=False):
    
    def format_node(n, extra=None, indent=0):
        """
        Depends on closure over `record` and `suppress_values`.

        Args:
          n (Evtx.Nodes.BXmlNode):
          extra (str):

        Returns:
          str:
        """
        ret = ""
        indent_s = '  ' * indent
        name = n.__class__.__name__
        offset = n.offset() - record.offset()
        if extra is not None:
            ret = "%s%s(offset=%s, %s)" % (indent_s, name, hex(offset), extra)
        else:
            ret = "%s%s(offset=%s)" % (indent_s, name, hex(offset))

        if not suppress_values and isinstance(n, VariantTypeNode):
            ret += " --> %s" % (n.string())
            if isinstance(n, BXmlTypeNode):
                ret += "\n"
                ret += describe_root(record, n._root, indent=indent + 1)

        return ret

    def rec(node, indent=0):
        """
        Args:
          node (Evtx.Nodes.BXmlNode):
          indent (int):

        Returns:
          str:
        """
        ret = ""
        if isinstance(node, TemplateInstanceNode):
            if node.is_resident_template():
                extra = "resident=True, length=%s" % (hex(node.template().data_length()))
                ret += "%s\n" % (format_node(node, extra=extra, indent=indent))
                ret += rec(node.template(), indent=indent + 1)
            else:
                ret += "%s\n" % (format_node(node, extra="resident=False", indent=indent))
        else:
            ret += "%s\n" % (format_node(node, indent=indent))

        for child in node.children():
            ret += rec(child, indent=indent + 1)

        if isinstance(node, RootNode):
            ofs = node.tag_and_children_length()
            indent_s = '  ' * (indent + 1)
            offset = node.offset() - record.offset() + ofs
            ret += "%sSubstitutions(offset=%s)\n" % (indent_s, hex(offset))
            for sub in node.substitutions():
                ret += "%s\n" % (format_node(sub, indent=indent + 2))

        return ret

    ret = ""
    ret += rec(root, indent=indent)
    return ret
1357520
def nodeDumpOutput(self, buf, cur, level, format, encoding):
        
        if buf is None: buf__o = None
        else: buf__o = buf._o
        if cur is None: cur__o = None
        else: cur__o = cur._o
        libxml2mod.xmlNodeDumpOutput(buf__o, self._o, cur__o, level, format, encoding)
771401
function normalize(node, method) {
		if (method === "prepend" || method === "append") {
			node.normalize();
		} else if (node.parentNode) {
			node.parentNode.normalize();
		}
	}
1122449
def as_xml(self):
        
        # Build tree
        spacing = ("\n" if (self.pretty_xml) else "")
        root = Element('error', {'xmlns': I3F_NS})
        root.text = spacing
        e_parameter = Element('parameter', {})
        e_parameter.text = self.parameter
        e_parameter.tail = spacing
        root.append(e_parameter)
        if (self.text):
            e_text = Element('text', {})
            e_text.text = self.text
            e_text.tail = spacing
            root.append(e_text)
        # Write out as XML document to return
        tree = ElementTree(root)
        xml_buf = io.BytesIO()
        if (sys.version_info < (2, 7)):
            tree.write(xml_buf, encoding='UTF-8')
        else:
            tree.write(xml_buf, encoding='UTF-8',
                       xml_declaration=True, method='xml')
        return(xml_buf.getvalue().decode('utf-8'))
345487
private void addRootElement() {
		Node root = helper.getRoot();
		if (root != null)
			result.add(root);
	}
60936
def _format_data(self, data, charset):
        

        if data is None or data == '':
            return u''

        stream = StringIO.StringIO()
        xml = SimplerXMLGenerator(stream, charset)
        xml.startDocument()
        xml.startElement(self._root_element_name(), {})
        self._to_xml(xml, data)
        xml.endElement(self._root_element_name())
        xml.endDocument()
        return stream.getvalue()