tools/metrics/histograms/merge_xml.py
def CombineHistogramsSorted(doc, trees):
  """Sorts histograms related nodes by name and returns the combined nodes.

  This function sorts nodes including <histogram>, <variant> and
  <histogram_suffix>. Then it returns one <histograms> that contains the
  sorted <histogram> and <variant> nodes and the other <histogram_suffixes_list>
  node containing all <histogram_suffixes> nodes.

  Args:
    doc: The document to create the node in.
    trees: A list of DOM trees.

  Returns:
    A list containing the combined <histograms> node and the combined
    <histogram_suffix_list> node.
  """
  # Create the combined <histograms> tag.
  combined_histograms = doc.createElement('histograms')

  def SortByLowerCaseName(node):
    return node.getAttribute('name').lower()

  variants_nodes = GetElementsByTagName(trees, 'variants', depth=3)
  sorted_variants = sorted(variants_nodes, key=SortByLowerCaseName)

  histogram_nodes = GetElementsByTagName(trees, 'histogram', depth=3)
  sorted_histograms = sorted(histogram_nodes, key=SortByLowerCaseName)

  for variants in sorted_variants:
    # Use unsafe version of `appendChild` function here because the safe one
    # takes a lot longer (10000x) to append all children. The unsafe version
    # is ok here because:
    #   1. the node to be appended is a clean node.
    #   2. The unsafe version only does fewer checks but not changing any
    #     behavior and it's documented to be usable if performance matters.
    #     See https://github.com/python/cpython/blob/2.7/Lib/xml/dom/minidom.py#L276.
    xml.dom.minidom._append_child(combined_histograms, variants)

  for histogram in sorted_histograms:
    xml.dom.minidom._append_child(combined_histograms, histogram)

  # Create the combined <histogram_suffixes_list> tag.
  combined_histogram_suffixes_list = doc.createElement(
      'histogram_suffixes_list')

  histogram_suffixes_nodes = GetElementsByTagName(trees,
                                                  'histogram_suffixes',
                                                  depth=3)
  sorted_histogram_suffixes = sorted(histogram_suffixes_nodes,
                                     key=SortByLowerCaseName)

  for histogram_suffixes in sorted_histogram_suffixes:
    xml.dom.minidom._append_child(combined_histogram_suffixes_list,
                                  histogram_suffixes)

  return [combined_histograms, combined_histogram_suffixes_list]
Sorts histograms related nodes by name and returns the combined nodes.

  This function sorts nodes including <histogram>, <variant> and
  <histogram_suffix>. Then it returns one <histograms> that contains the
  sorted <histogram> and <variant> nodes and the other <histogram_suffixes_list>
  node containing all <histogram_suffixes> nodes.

  Args:
    doc: The document to create the node in.
    trees: A list of DOM trees.

  Returns:
    A list containing the combined <histograms> node and the combined
    <histogram_suffix_list> node.
  
Sorts histograms related nodes by name and returns the combined nodes.
This function sorts nodes including ,  and
. Then it returns one  that contains the
sorted  and  nodes and the other 
node containing all  nodes.
Sorts histograms related nodes by name and returns the combined nodes . This function sorts nodes including and . Then it returns one that contains the sorted and nodes and the other node containing all nodes .
def CombineHistogramsSorted(doc, trees):
  combined_histograms = doc.createElement('histograms')
  def SortByLowerCaseName(node):
    return node.getAttribute('name').lower()
  variants_nodes = GetElementsByTagName(trees, 'variants', depth=3)
  sorted_variants = sorted(variants_nodes, key=SortByLowerCaseName)
  histogram_nodes = GetElementsByTagName(trees, 'histogram', depth=3)
  sorted_histograms = sorted(histogram_nodes, key=SortByLowerCaseName)
  for variants in sorted_variants:
    xml.dom.minidom._append_child(combined_histograms, variants)
  for histogram in sorted_histograms:
    xml.dom.minidom._append_child(combined_histograms, histogram)
  combined_histogram_suffixes_list = doc.createElement(
      'histogram_suffixes_list')
  histogram_suffixes_nodes = GetElementsByTagName(trees,
                                                  'histogram_suffixes',
                                                  depth=3)
  sorted_histogram_suffixes = sorted(histogram_suffixes_nodes,
                                     key=SortByLowerCaseName)
  for histogram_suffixes in sorted_histogram_suffixes:
    xml.dom.minidom._append_child(combined_histogram_suffixes_list,
                                  histogram_suffixes)
  return [combined_histograms, combined_histogram_suffixes_list]
def CombineHistogramsSorted ( doc , trees ) : combined_histograms = doc . createElement ( 'histograms' ) def SortByLowerCaseName ( node ) : return node . getAttribute ( 'name' ) . lower ( ) variants_nodes = GetElementsByTagName ( trees , 'variants' , depth = 3 ) sorted_variants = sorted ( variants_nodes , key = SortByLowerCaseName ) histogram_nodes = GetElementsByTagName ( trees , 'histogram' , depth = 3 ) sorted_histograms = sorted ( histogram_nodes , key = SortByLowerCaseName ) for variants in sorted_variants : xml . dom . minidom . _append_child ( combined_histograms , variants ) for histogram in sorted_histograms : xml . dom . minidom . _append_child ( combined_histograms , histogram ) combined_histogram_suffixes_list = doc . createElement ( 'histogram_suffixes_list' ) histogram_suffixes_nodes = GetElementsByTagName ( trees , 'histogram_suffixes' , depth = 3 ) sorted_histogram_suffixes = sorted ( histogram_suffixes_nodes , key = SortByLowerCaseName ) for histogram_suffixes in sorted_histogram_suffixes : xml . dom . minidom . _append_child ( combined_histogram_suffixes_list , histogram_suffixes ) return [ combined_histograms , combined_histogram_suffixes_list ]
Sorts histograms related nodes by name and returns the combined nodes.
Sorts histograms related nodes by name and returns the combined nodes .
"""Sorts histograms related nodes by name and returns the combined nodes.

  This function sorts nodes including <histogram>, <variant> and
  <histogram_suffix>. Then it returns one <histograms> that contains the
  sorted <histogram> and <variant> nodes and the other <histogram_suffixes_list>
  node containing all <histogram_suffixes> nodes.

  Args:
    doc: The document to create the node in.
    trees: A list of DOM trees.

  Returns:
    A list containing the combined <histograms> node and the combined
    <histogram_suffix_list> node.
  """ # Create the combined <histograms> tag. # Use unsafe version of `appendChild` function here because the safe one # takes a lot longer (10000x) to append all children. The unsafe version # is ok here because: #   1. the node to be appended is a clean node. #   2. The unsafe version only does fewer checks but not changing any #     behavior and it's documented to be usable if performance matters. #     See https://github.com/python/cpython/blob/2.7/Lib/xml/dom/minidom.py#L276. # Create the combined <histogram_suffixes_list> tag.
A list containing the combined  node and the combined
 node.
A list containing the combined node and the combined node .
doc
The document to create the node in.
The document to create the node in .
trees
A list of DOM trees.
A list of DOM trees .