[jdom-commits] I have a problem

=?gb2312?q?=B7=EB=D3=F1=E7=F4?= fengyuxi at yahoo.com.cn
Mon Sep 16 00:00:51 PDT 2002


hello everyOne:
  now, i use jdom parse my xml document. I write a
method for get all Element with JAVA. this is the 
source:

  public List getAllChildren(Element root) {
    try {
      Element elementRoot = root;

      List listElements = elementRoot.getChildren();

      Iterator itElements = listElements.iterator();
      while (itElements.hasNext()) {
        Element elementChild =
(Element)itElements.next();

        List listChildren =
getAllChildren(elementChild);

        Iterator itChildren = listChildren.iterator();
        while (itChildren.hasNext()) {
          listElements.add(itChildren.next());
        }
      }

      return listElements;
    } catch(Exception Exp) {
Exp.printStackTrace(System.out);
      return null;
    }
  }

  But, i get a Exception called
"org.jdom.IllegalAddException". the Exception was
throwed from ContentList. I find the Error line is
189, this is source in ContentList:

        if (element.getParent() != null) {
            throw new IllegalAddException(
                          "The element already has an
existing parent \"" +
                         
element.getParent().getQualifiedName() + "\"");
        }

I want know, why the ContentList don't allow a Element
who's parent in the contentlist be add into the
contentlist???

                   thanks

                          Moses Feng

                         fengyuxi at yahoo.com.cn


_________________________________________________________
Do You Yahoo!? 
ÐÂÏʵ½µ×,ÓéÀÖµ½¼Ò - ÑÅ»¢ÍƳöÃâ·ÑÓéÀÖµç×ÓÖܱ¨!
http://cn.ent.yahoo.com/newsletter/index.html



More information about the jdom-commits mailing list