weimingtom / minijoe

Automatically exported from code.google.com/p/minijoe
1 stars 0 forks source link

Element.getChildById(String id) is not correct #23

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
public Element getChildById(String id) {
     int childCount = this.getChildCount();
      Element currChild = null;
      for (int i=0; i < childCount; i++) {
          if (this.getChildType(i) == this.ELEMENT) {
              currChild = this.getElement(i);             
              if (currChild != null && 
                      id.equals(currChild.getAttributeValue("id"))
                      ) {
                  break;
              } else if (currChild.getChildCount() > 0) {
                  currChild.getChildById(id);
              }               
          }
      }
      return currChild;
  }

Above is the current implementation. If there is no child element with the 
specified id, the function will traverse through and return the last child. Am 
I right?

Original issue reported on code.google.com by HaiLe...@gmail.com on 26 Dec 2010 at 12:35