Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

remove a node from xml document in Java

Posted on 2015-01-25
1
Medium Priority
?
273 Views
Last Modified: 2015-01-26
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
0
Comment
Question by:sniger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

Accepted Solution

by:
Amitkumar Panchal earned 2000 total points
ID: 40570879
Give it a try with the following. Few things left for you to complete.


                  builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                  document = builder.parse(new FileInputStream(xmlFile));
                  document.getDocumentElement().normalize();
                  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
                                    }
                  }
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question