code: def combine(files):
      impl = getDOMImplementation()
      doc = impl.createDocument(None, "svg", None)
      defs = doc.createElement("defs")
      doc.documentElement.appendChild(defs)
      svgs_to_insert = []
      for filename in files:
          partial_doc = minidom.parse(filename)
          partial_defs = partial_doc.getElementsByTagName("defs")
          if partial_defs:
              if len(partial_defs) > 1:
                  raise ValueError(
                      "Unexpected document structure. Expected only one `<defs>`"
                      "in '%s'." % filename
                  )
              svgs_to_insert.extend(partial_defs[0].childNodes)
          else:
              maybe_svg_el = partial_doc.documentElement
              if maybe_svg_el.tagName != "svg":
                  raise ValueError(
                      "Unexpected document. Expected '%s' to start with <svg>."
                      % filename
                  )
              svg_el = maybe_svg_el
  
              basename = path.basename(filename)
              svg_el.setAttribute("id", path.splitext(basename)[0])
              svgs_to_insert.append(svg_el)
  
      svg_ids = set()
      duplicate_ids = set()
      for partial_svg in svgs_to_insert:
          svg_id = partial_svg.getAttribute("id")
          if not svg_id:
              raise ValueError(
                  "Unexpected document type: expected SVG inside defs contain "
                  "`id` attribute."
              )
  
          if svg_id in svg_ids:
              duplicate_ids.add(svg_id)
  
          svg_ids.add(svg_id)
          defs.appendChild(partial_svg)
  
      if duplicate_ids:
          raise ValueError(
              "Violation: SVG with these ids appeared more than once in `srcs`: "
              + ", ".join(duplicate_ids),
          )
  
      return doc.toxml()
  
imports: from os import path
  from xml.dom import getDOMImplementation
  from xml.dom import minidom
  import sys
label_desc: Use image node_id 1 for calling a global function with example usage: combine(files) and returns: doc