code: public static void removeNodesByTagName(Element doc, String tagname) {
      NodeList nodes = doc.getElementsByTagName(tagname);
      for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        doc.removeChild(n);
      }
    }
docs: Removes elements by a specified tag name from the xml Element passed in.
  @param doc The xml Element to remove from.
  @param tagname The tag name to remove.