title: How to remove only the parent element and not its child elements in Python?
body: <p>A similar question to the one in JavaScript</p>
  
  <p>I have a xml and want to comment just the parent tag without its children
  like in the example below:</p>
  
  <pre><code>&lt;object id="12"&gt;
   &lt;process name="Developer"&gt;
    &lt;appdef&gt;
     &lt;attributes&gt;
      &lt;attribute name="X"&gt;
          &lt;ProcessValue datatype="number" value="15" /&gt;
      &lt;/attribute&gt;
      &lt;attribute name="Y"&gt;
          &lt;ProcessValue datatype="number" value="59" /&gt;
      &lt;/attribute&gt;
     &lt;/attributes&gt;
    &lt;/appdef&gt;
   &lt;/process&gt;
  &lt;/object&gt;
  </code></pre>
  
  <p>and comment just &lt; object > tags</p>
  
  <pre><code>&lt;!--&lt;object id="12"&gt;--&gt;
   &lt;process name="Developer"&gt;
     &lt;appdef&gt;
       &lt;attributes&gt;
         &lt;attribute name="X"&gt;
          &lt;ProcessValue datatype="number" value="15" /&gt;
         &lt;/attribute&gt;
         &lt;attribute name="Y"&gt;
          &lt;ProcessValue datatype="number" value="59" /&gt;
         &lt;/attribute&gt;
       &lt;/attributes&gt;
     &lt;/appdef&gt;
   &lt;/process&gt;
  &lt;!--&lt;/object&gt;--&gt;
  </code></pre>
  
  <p>I have a code to comment the tag but it comment all its children also.</p>
  
  <p>Thank you very much I appreciate any help</p>
  
  <p>Due to confusions I am attaching the whole code:</p>
  
  <pre><code>from xml.dom import minidom
  
  
  xml = """\
    &lt;bpr:release xmlns:bpr="http://www.blueprism.co.uk/product/release"&gt;
     &lt;object id="0e694daf-836e-44a9-816a-9b8127abb7b2" name="Developer 2 
       ex" xmlns="http://www.blueprism.co.uk/product/process"&gt;
      &lt;process name="Developer 2 ex" version="1.0" bpversion="5.0.33.0" 
        narrative="BO for automation the HTML page&amp;#xD;&amp;#xA;" type="object" 
         runmode="Exclusive"&gt;
          &lt;appdef&gt;
              &lt;attributes&gt;
                  &lt;attribute name="X"&gt;
                      &lt;ProcessValue datatype="number" value="15" /&gt;
                  &lt;/attribute&gt;
                  &lt;attribute name="Y"&gt;
                      &lt;ProcessValue datatype="number" value="59" /&gt;
                  &lt;/attribute&gt;
              &lt;/attributes&gt;
          &lt;/appdef&gt;
         &lt;/process&gt;
        &lt;/object&gt;
      &lt;/bpr:release&gt;
      """
  
  def comment_node(node):
      comment = node.ownerDocument.createComment(node.toxml())
      print(comment)
      node.parentNode.replaceChild(comment, node)
      return comment
  
  
  doc = minidom.parseString(xml).documentElement
  
  comment_node(doc.getElementsByTagName('object')[-1])
  
  xml = doc.toxml()
  </code></pre>