I have the following XML from which I am trying to remove the whole node if the status matched DEACTIVATED.

Below is the **input.xml**

```
<devicesInfo>
    <deviceID>DEVICE1</deviceID>
    <secondaryDevice>false</secondaryDevice>
    <status>ACTIVE</status>
</devicesInfo>
<devicesInfo>
    <deviceID>DEVICE2</deviceID>
    <secondaryDevice>false</secondaryDevice>
    <status>DEACTIVATED</status>
</devicesInfo>
<devicesInfo>
    <deviceID>DEVICE3</deviceID>
    <secondaryDevice>false</secondaryDevice>
    <status>ACTIVE</status>
</devicesInfo>
<devicesInfo>
    <deviceID>DEVICE4</deviceID>
    <secondaryDevice>false</secondaryDevice>
    <status>ACTIVE</status>
</devicesInfo>

```

**And the desired output to be:**

```
<devicesInfo>
    <deviceID>DEVICE1</deviceID>
    <secondaryDevice>false</secondaryDevice>
    <status>ACTIVE</status>
</devicesInfo>
<devicesInfo>
    <deviceID>DEVICE3</deviceID>
    <secondaryDevice>false</secondaryDevice>
    <status>ACTIVE</status>
</devicesInfo>
<devicesInfo>
    <deviceID>DEVICE4</deviceID>
    <secondaryDevice>false</secondaryDevice>
    <status>ACTIVE</status>
</devicesInfo>

```

I have already been able to extract the deviceID that match the status **DEACTIVATED** but struggling in deleting the whole node

```
void removeDeactivatedDevices() throws SAXException, IOException, ParserConfigurationException {
        String device;
        try {
            File inputFile = new File(input.xml);
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(inputFile);

            doc.getDocumentElement().normalize();
            NodeList nList = doc.getElementsByTagName("devicesInfo");

            for (int i = 0; i < nList.getLength(); i++) {
                Node nNode = nList.item(i);

                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;

                    if (eElement.getElementsByTagName("status").item(0).getTextContent().contentEquals("DEACTIVATED")) {
                        device = eElement.getElementsByTagName("deviceID").item(0).getTextContent();

                        // print out the devices that match this status
                        System.out.println(device);

                                  // HELP Need to delete parent node of that device...
                    }

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

```

So, when I run it I get:

```
DEVICE1
DEVICE3
DEVICE4

```

What I want is the full XML returned without the DEACTIVATED Status items.