私は、以下の構造を持つXMLファイルを持っている:JDOMを使用してJDOMを使用して要素をその属性で削除しますか?
<contacts>
<contact id="0">
<firstname />
<lastname />
<address>
<street />
<city />
<state />
<zip />
<country />
</address>
<phone />
<email />
<continfo>
<byemail />
<byphone />
<bymail />
</continfo>
<comments />
<datecreated />
</contact>
</contacts>
を、私はid属性を調べることにより、全体の接触要素とそのすべての子を削除したいです。しかし、私はこれを理解することにいくつかの問題を抱えています。私は以下を試しました:
Element pageRoot = pageXML.getRootElement();
List<Element> contacts = new ArrayList<Element>(pageRoot.getChildren());
Element contact = null;
for(Element element : contacts){
String att = element.getAttributeValue("id");
if(Integer.parseInt(att) == id){
contact = (Element) element.clone();
}
}
pageRoot.removeContent(contact);
しかし、その連絡先は決して削除されません。誰かが私をある方向に向けることができれば、それは素晴らしいことだろう。ありがとうございました。
から構成されている..あなたに感謝。 – Cuthbert