Search code examples
javadomw3c

Is there a standard way to get all elements with a class name WITHIN a certain node?


I know of Document.getElementsByClassname(String) to get all elements of a specific class name in the entire document.

I'm now trying to get those elements within a specific node of the document. In the org.w3c.dom.Element, I only find getElementsByTagname. Do I really need to iterate over all these elements and read the class name, or is there a better way?

I'm trying to find a solution using Java only (can be with another library).

Thanks a lot!


Solution

  • I ended up using JSoup, which contains the method I need.

    http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#getElementsByClass%28java.lang.String%29