remove a node from xml document in Java

I'm using  javax.xml.parsers.DocumentBuilder and would like to preprocess my xml document by removing a node  <Status > </Status> if it has
any following same siblings.

For example  <Status>   <Ins>    XXX  </Ins>      </Status>
                        <Status>    <Ins>    YYY  </Ins>    </Status>

I want to get rid of YYY
Who is Participating?
Amitkumar PConnect With a Mentor Sr. ConsultantCommented:
Give it a try with the following. Few things left for you to complete.

                  builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                  document = builder.parse(new FileInputStream(xmlFile));
                  xpath = XPathFactory.newInstance().newXPath();
                  NodeList nodeList = (NodeList) xpath.evaluate("/Status/Ins", document.getDocumentElement(), XPathConstants.NODESET);
                  for (int index=0; index<nodeList.getLength(); ++index) {
                        Node node = nodeList.item(index);
                                    if (node!=null && node.getNodeType()==Node.XXXXX_NODE) {
                                          // TODO do removal activity
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.