[jdom-interest] Child number

KhanhVinh Tran kvtran999 at yahoo.com
Wed Apr 17 07:48:21 PDT 2002


Thanks everyone for your advice.
My data is more complicated than what I put in the
previous sample.

Let's me make it clear.
ex:
<sample>        
  <child> 
    <name> A </name>
    <description> Andrew </description>
      <grandchild> 
        <name> A1 </name>
        <description> Andrew1 </description>     
      </grandchild>
      <grandchild> 
        <name> A2 </name>
        <description> Andrew2 </description>     
      </grandchild>
      ...
  </child>
  <child> 
    <name> B </name>
    <description> Brian </description>
      <grandchild> 
        <name> B1 </name>
        <description> Brian1 </description>     
      </grandchild>
      <grandchild> 
        <name> B2 </name>
        <description> Brian2 </description>     
      </grandchild>
      ...
  </child>
  ...
</sample>

It's complicated like above.  So if I know the child#,
the remove(child#) method will let me remove the whole
thing.  
For ex: allChildren.remove(1)
        This will remove child A and all grandchildren

Thanks!

--- Noam Tamim <noamt at yahoo.com> wrote:
> 
> Something as simple as
> 
> Iterator it=allChildren.iterator();
> while (it.hasNext()) {
>  if ( ((Element)it.next()).getTextTrim().equals("B")
> ) it.remove();
> }
> 
> will do the job. You DON'T need to know the number,
> as the Iterator
> supports removing elements.
> 
> 
> > > I have a XML doc as below:
> > > 
> > > <sample>
> > >        <child> A </child>
> > >        <child> B </child>
> > >        <child> C </child>
> > >        ...
> > > </sample>
> > > 
> > > How do I know "B" is the text of the 2rd child?
> > > I need to know the child number so I can use
> > > the method remove(int child#).
> > > Ex: allChildren.remove(3) //remove the third
> child
> 
> 
> 
> =====
> Noam.
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/



More information about the jdom-interest mailing list