[jdom-interest] Remove elements--Finally works!!!

Ladhani, Dilip dladhani at gltg.com
Tue Jun 18 14:18:43 PDT 2002


I got this working finally. I was checking the original XML, which was unchanged. However when I used the XML outputter, the desired sections have been removed.
 
Thanks for your time Alex and John.

	-----Original Message----- 
	From: Ladhani, Dilip 
	Sent: Tue 6/18/2002 2:12 PM 
	To: John L. Webber - Jentro AG; jdom-interest at jdom.org 
	Cc: jdom-interest at jdom.org 
	Subject: RE: [jdom-interest] Remove elements
	
	

	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
	        ---------------------------------------------------------
	       
	
	_______________________________________________
	To control your jdom-interest membership:
	http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
	




More information about the jdom-interest mailing list