The list of methods to do XML Node Remove are organized into topic(s).
void
removeAll(final Node node, final short nodeType, final String name) Remove named nodes of the specified nodeType from the specified node.
if (node.getNodeType() == nodeType && (name == null || node.getNodeName().equals(name))) {
node.getParentNode().removeChild(node);
} else {
final NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
removeAll(list.item(i), nodeType, name);
void
removeAll(Node node) remove All
while (node.getChildNodes().getLength() > 0) {
node.removeChild(node.getFirstChild());
void
removeAll(Node node, short nodeType, String name) remove All
if (node == null) {
return;
if (node.getNodeType() == nodeType && (name == null || node.getNodeName().equals(name))) {
node.getParentNode().removeChild(node);
} else {
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
...
void
removeAll(Node node, short nodeType, String name) remove All
if (node.getNodeType() == nodeType && (name == null || node.getNodeName().equals(name))) {
node.getParentNode().removeChild(node);
} else {
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
removeAll(list.item(i), nodeType, name);
void
removeContents(Node parent) remove Contents
Node node = parent.getFirstChild();
while (node != null) {
parent.removeChild(node);
node = node.getNextSibling();
void
removeElement(Element parent, String tagName) Remove the node from parent
NodeList nl = parent.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node nd = nl.item(i);
if (nd.getNodeName().equals(tagName)) {
parent.removeChild(nd);
void
removeElements(Node parent, String nature) Removes all elements with a given nature (as content).
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (checkNature(child, nature)) {
parent.removeChild(child);
} else {
removeElements(child, nature);
...
void
removeElementXML(Node node, short nodeType, String name) remove Element XML
if (node.getNodeType() == nodeType && (name == null || node.getNodeName().equals(name))) {
node.getParentNode().removeChild(node);
} else {
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
removeElementXML(list.item(i), nodeType, name);
void
removeEmptyHeadings(Node root) remove Empty Headings
NodeList hNodes = ((Element) root).getElementsByTagName("text:h");
for (int i = 0; i < hNodes.getLength(); i++) {
Node node = hNodes.item(i);
if (node.getChildNodes().getLength() > 0) {
boolean empty = true;
for (int j = 0; j < node.getChildNodes().getLength(); j++) {
if (!node.getChildNodes().item(j).getTextContent().trim().equals("")) {
empty = false;
...
void
removeEmptyHeadings(Node root) Remove empty
text:h elements.
NodeList hNodes = ((Element) root).getElementsByTagName("text:h");
for (int i = 0; i < hNodes.getLength(); i++) {
Node node = hNodes.item(i);
if (node.getChildNodes().getLength() > 0) {
boolean empty = true;
for (int j = 0; j < node.getChildNodes().getLength(); j++) {
if (!node.getChildNodes().item(j).getTextContent().trim().equals("")) {
empty = false;
...