Here is my code. It removes cubes comparing cube attribute "name" against a value I passed as a variable to the method. But the issue is it change other nodes (dimension,other ) in the xml file.
<schema>
<dimension..../>
<cube name="..." .../>
<others ..>
</schema>
What I can do to prevent other nodes getting changed ?
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
String expressionQuery = String.format("//Schema/Cube[@name=\"%s \"]",cubeName);
XPathExpression expression = xpath.compile(expressionQuery);
Node nodeToRemove = (Node) expression.evaluate(document, XPathConstants.NODE);
if(nodeToRemove != null) {
nodeToRemove.getParentNode().removeChild(nodeToRemove);
}