Java - Dom4j-problema

 
Vista:

Dom4j-problema

Publicado por Alejandra (2 intervenciones) el 23/11/2007 14:37:41
Quiero quitar un nodo Channel del siguiente XML:

<?xml version=
"1.0" encoding="UTF-8"?>
<MiTV context="EPG:Next">
<ReturnCode>0</ReturnCode>
<ReturnMessage>Your request was successful...</ReturnMessage>
<Channel>
<ChannelId>MiTeleTV_4_DEM_19</ChannelId>
<ChannelName nav="1">Antena 3</ChannelName>
<ChannelLogo nav="1">http://localhost/IMG_MITV/channel/MiTeleTV_4.jpg</ChannelLogo>
</Channel>
<Channel>
<ChannelId>MiViewTV_2_DEM_19</ChannelId>
<ChannelName nav="1">La 2</ChannelName>
<ChannelLogo nav="1">http://localhost/IMG_MITV/channel/MiTeleV_153.jpg</ChannelLogo>
</Channel>
....

cuando uso el metodo clearContent(); para borrrar por ejemplo el 2o canal, me deja el tag
<Channel/>

private static Document removeListChannels(Document doc, List<String> cForRemove) {
List nolist = null;
nolist = doc.selectNodes("//MiTV/Channel");
Iterator it = nolist.iterator();
while (it.hasNext()) {
Element e = (Element) it.next();
Iterator iterator = e.elementIterator("ChannelId");
while (iterator.hasNext()) {
Element lastNameElement = (Element) iterator.next();
int i = 0;
for (i = 0; i < cForRemove.size(); i++) {
if (lastNameElement.getText().equals(cForRemove.get(i))) {
Element ele = lastNameElement.getParent();
ele.clearContent();

}
}
}
}
doc.normalize();
log.debug("normalize");
return doc;
}

<?xml version=
"1.0" encoding="UTF-8"?>
<MiTV context="EPG:Next">
<ReturnCode>0</ReturnCode>
<ReturnMessage>Your request was successful...</ReturnMessage>
<Channel>
<ChannelId>MiViewTV_4_DEM_19</ChannelId>
<ChannelName nav="1">Antena 3</ChannelName>
<ChannelLogo nav="1">http://localhost/IMG_MITV/channel/MiTele_4.jpg</ChannelLogo>
</Channel>
<Channel/> <------------------------------PROBLEMA
....

Como puedo borrarlo que no quede el <Channel7> ? Gracias por adelantado

Alejandra
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder