[jdom-interest] Remove all occurencies of an element

Niels Peter Strandberg nielspeter at npstrandberg.com
Sun Mar 25 04:16:29 PST 2001


Remove all occurencies of an element

I have some rather complex XML documents that I want to reduces, by removing the "unwanted" elements and attributes.

Example 1: (removing both the element and text node)

<A>
       <B>
              <C>
                     <D>
                            <C/>
                     </D>
              </C>
       </B>
</A>

The wanted result 1: (after all the C-elements are removed from the document )

<A>
       <B>
              <D>
              </D>
       </B>
</A>


Example 2: (removing the C-element but keeping the text node)

<A>
       <B>
              <C>
                     <D>The 
                            <C>blue </C>
                     </D>color is ....
              </C>
       </B>
</A>

The wanted result 2: (after the C-element is removed)

<A>
       <B>
              <D>
                     The blue color is ....
              </D>
       </B>
</A>

To my understanding the removeChildren(java.lang.String name) removes the children one level deep and it also removes the childrens children. So this can't be used.

Does any one have an idéar how to do this?

Regards, Niels Peter



More information about the jdom-interest mailing list