[jdom-interest] Trimming a jdom tree

Noam Tamim noamt at yahoo.com
Mon Apr 1 07:50:27 PST 2002


Hi.

I wrote a little method that trims all Strings of a jdom tree (recursively).
Do you think there's more to it?

    static void trim(Element e) {
        Iterator iter=e.getContent().iterator();
        
        while (iter.hasNext()) {
            Object o=iter.next();
            if (o instanceof Text) {
                Text text=(Text)o;
                String str=text.getTextTrim();
                if (str.length()>0) {
                    text.setText(str);
                }
                else {
                    iter.remove();
                }
            }
            else if (o instanceof Element) {
                trim((Element)o);
            }
        }
    }


=====
Noam.

__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/



More information about the jdom-interest mailing list