Re: Problem with implementation of getChildNodes on HTMLFormElement?

Petr Stehlik <[email protected]> Fri, 12 Sep 2003 19:06:18 +0200
Newsgroups gmane.comp.java.enhydra.xmlc
Message-ID <[email protected]>
V St, 10. 09. 2003 v 22:53, Jacob Kjome píše:
> Thanks for the testcase.  I have replicated the behavior but, like you, I'm 
> not sure what exactly is causing it.  It should definitely be figured 
> out.

I experienced something similar with a function that traverses the DOM 
and returns all nodes that have class with a given name:

public static Vector getByClassName(Node node, String className) {
  Vector elems = new Vector();
  NodeList children = node.getChildNodes();
  for (int i=0; i<children.getLength();i++) {
    elems.addAll(getByClassName(children.item(i), className));
  }
  if (node instanceof HTMLElement) {
    String elemClassName = ((HTMLElement)node).getClassName();
    if ((elemClassName != null) && elemClassName.equalsIgnoreCase(className)) {
      elems.add((HTMLElement)node);
    }
  }
  return elems;
}

This works fine on several pages but I also have one page where this
doesn't work - doesn't return any node eventhough there are several ones
with the class set.

I never figured out why it doesn't work. I could probably create a
testcase from the html page and share it as well.

Petr

P.S. Would be nice to fix this issue and release XMLC 2.2.1 that would
be a drop-in replacement for the XMLC in (at that time probably
released) Enhydra 5.1 :) Yes I really appreciate the new modular
structure of Enhydra 5.1 :))