title: Removing xml tags by using java
body: <p>I have a very simple xml file that I would like to create a simple function to remove a tag from it. Here is my sample xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rss version="2.0"&gt;
      &lt;channels&gt;
          &lt;channel&gt;
              &lt;items&gt;
                  &lt;item&gt;
                      &lt;title&gt;Java Tutorials&gt;&lt;/title&gt;
                      &lt;link&gt;http://www.tutorial-point.com/&lt;/link&gt;
                  &lt;/item&gt;
                  &lt;item&gt;
                      &lt;title&gt;Java Tutorials&gt;&lt;/title&gt;
                      &lt;link&gt;http://www.javatpoint.com/&lt;/link&gt;
                  &lt;/item&gt;
              &lt;/items&gt;
          &lt;/channel&gt;
      &lt;/channels&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>In my Java program, simply want to call a method to delete two tags from the file. I'm not very familiar with XML but did manage to create a reader and writer but now I'm having trouble creating a method to delete an item from my file.</p>
  
  <pre><code>    // retrieve the element 
      Element element = (Element) doc.getElementsByTagName("channels").item(0);
      Element element2 = (Element) doc.getElementsByTagName("channel").item(0);
      // remove the specific node
      element.getParentNode().removeChild(element);
      element2.getParentNode().removeChild(element2);
  </code></pre>
  
  <p>When I used the above code in Java, it removed all the tags but I expected the result like below: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rss version="2.0"&gt;
      &lt;items&gt;
          &lt;item&gt;
              &lt;title&gt;Java Tutorials&gt;&lt;/title&gt;
              &lt;link&gt;http://www.tutorial-point.com/&lt;/link&gt;
          &lt;/item&gt;
          &lt;item&gt;
              &lt;title&gt;Java Tutorials&gt;&lt;/title&gt;
              &lt;link&gt;http://www.javatpoint.com/&lt;/link&gt;
          &lt;/item&gt;
      &lt;/items&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>Can you please suggest?</p>