[jdom-interest] Remove elements

Ladhani, Dilip dladhani at gltg.com
Tue Jun 18 11:12:32 PDT 2002


I switched to version 8 beta. However nothing seems to work.
I tried
iSections.remove();
 
also tried
dataRs.removeContent(elemSection)
 
The underlying XML String (it's not a file) doesn't change at all. I also am trying to use setText on an element and that doesn't work either.
 
Baasically the XML string doesn't change!!!!
 
Any ideas???? 

	-----Original Message----- 
	From: John L. Webber - Jentro AG [mailto:John.Webber at jentro.com] 
	Sent: Tue 6/18/2002 2:35 AM 
	To: Ladhani, Dilip 
	Cc: jdom-interest at jdom.org 
	Subject: Re: [jdom-interest] Remove elements
	
	

	Hi Dilip,
	
	You need to remove the elements from their parent element, not from the
	list. Try
	
	dataRs.removeContent(elemSection);
	
	or, if you want to use the element somewhere else
	
	Element freeElement = elemSection.detach();
	//Now you can insert freeElement into another element.
	
	The API docs have plenty of information about this.
	
	Regards,
	
	John
	
	
	"Ladhani, Dilip" wrote:
	
	> I am trying to remove some elements from an xml doc based on some logic. Heres a sample of what I am doing.
	>
	> List listSections = dataRs.getChildren("ABC");
	> Iterator iterSections = listSections.iterator();
	> while(iterSections.hasNext()){
	> elemSection =  (Element) iterSections.next();
	> if(elemSection.getChildTextTrim("HDG").equalsIgnoreCase("XYX"){
	>         iterSections.remove();
	> }
	> }
	>
	> After this, when I try to print the xml, the elements which are supposed to be removed are still present!! I also tried using listSections.detach() instead of iterSections.remove(), but that didn't work either.
	> What am I doing wrong????
	>
	> In general, how do I remove elements??
	
	--
	---------------------------------------------------------
	 Jentro AG
	 John L. Webber, Software Development
	---------------------------------------------------------
	 Peter-Henlein-Strasse 28, 85540 Haar/Munich, Germany
	 Tel. +49 89 462 385 0     mailto:John.Webber at jentro.com
	 Fax  +49 89 462 385 29    http://www.jentro.com
	---------------------------------------------------------
	




More information about the jdom-interest mailing list