Search code examples
javaxmlxom

XOM and getChildElements


I use this piece of Java with the XOM library to parse a sitemap.

Element root = doc.getRootElement();
Elements urls = root.getChildElements("url");

When I'm debugging, I can see that root has a whole bunch of children, both url elements and text elements. However, root.getChildElements("url") returns an empty list.

What am I doing wrong?


Solution

  • I just realized that the sitemap I'm parsing uses a default namespace, which is "http://www.sitemaps.org/schemas/sitemap/0.9".

    Changing the code to root.getChildElements("url", "http://www.sitemaps.org/schemas/sitemap/0.9") gives me the right result.