xml から子要素を削除したい。
私のXMLファイルは
<mcss>
<quest ans="0">
<question><![CDATA[ This is question one]]></question>
<options>
<option><![CDATA[B<Option one]]></option>
<option><![CDATA[B<Option second]]></option>
<option><![CDATA[B<Option three]]></option>
</options>
<explaination><![CDATA[explaination one]]></explaination>
</quest>
<quest ans="0">
<question><![CDATA[ This is question two]]></question>
<options>
<option><![CDATA[B<Option one]]></option>
<option><![CDATA[B<Option second]]></option>
<option><![CDATA[B<Option three]]></option>
</options>
<explaination><![CDATA[explaination two]]></explaination>
</quest>
</mcss>
最初に質問を削除したい場合、どうすればよいですか? 出力XML..
<?xml version="1.0" encoding="UTF-8"?>
<mcss>
<quest ans="0">
<question><![CDATA[ This is question two]]></question>
<options>
<option><![CDATA[B<Option one]]></option>
<option><![CDATA[B<Option second]]></option>
<option><![CDATA[B<Option three]]></option>
</options>
<explaination><![CDATA[explaination two]]></explaination>
</quest>
</mcss>
質問1を削除する私のJavaコード。
String path="D://test//N2074_set2.xml";
File structureXml = new File(path);
SAXBuilder saxb = new SAXBuilder();
Document document = saxb.build(structureXml);
Element rootElement = document.getRootElement();
XMLOutputter xmlOutput = new XMLOutputter();
for (int i = 0; i < qestList.size(); i++) {
Element quesList = (Element) qestList.get(2);
if(quesList.getName().equalsIgnoreCase("quest"))
rootElement.removeContent(2);
}
FileOutputStream file=new FileOutputStream(path);
xmlOutput.output(document, file);