This is my xml document:
<definitions>
<task name="TASK1"
class="CLASS"
group="GROUP">
<trigger count="3" interval="400"/>
<property xmlns:task="URI"
name="PROPERTY2"
value="VALUE1"/>
<property xmlns:task="URI"
name="PROPERTY2"
value="VALUE2"/>
</task>
<task name="TASK1"
class="CLASS"
group="GROUP">
<trigger count="1" interval="600"/>
<property xmlns:task="URI"
name="PROPERTY2"
value="VALUE1"/>
<property xmlns:task="URI"
name="PROPERTY2"
value="VALUE2"/>
</task>
<another_tag name="a_name"/>
<another_tag2 name="a_name2"/>
<another_tag3> something in the middle </another_tag3>
</definitions>
I have to delete all <task>
tags and what inside them. I used this java code:
Document esb = new Document();
SAXBuilder saxBuilder = new SAXBuilder();
try {
esb = saxBuilder.build(new File("C:\\...path\\file.xml"));
}
catch (JDOMException ex) {
System.err.println(ex);
}
catch (IOException ex) {
System.err.println(ex);
}
Element root = esb.getRootElement();
boolean b = root.removeChild("task");
System.out.println(b);
I can't understand how to obtain an xml file without <task>
tag and containing only <another_tag>
tag. I've looked for other solutions but nothing useful. I also used removeContent() method, but nothing. I imported jdom2 libraries, I need to use recent libraries, because there are bad interactions among jdom and jdom2, so I would prefer to use recent libraries only. Any suggest about how to remove some element from this xml CODE?