Namespace / elements statistics

exercise No. 21

Create comment in forum


Consider the following XML document example:

<xsl:stylesheet xmlns:xsl=""

    <xsl:output method="xhtml"/>

    <xsl:template match="/">
        <html xmlns="">
                <meta charset="utf-8" />
                <h2>HTML5 SVG Circle</h2>
                <p>Starting a simple test.</p>
                <svg width="200" height="200" xmlns="">
                    <circle id="redcircle" cx="50" cy="50" r="50" fill="red" />
                <p>Ending a simple test.</p>

    <xsl:template match="*">
            <xsl:text>No rule defined for element '</xsl:text>
            <xsl:value-of select="name(.)"/>


The above sample document does contain elements belonging to three different namespaces:

Having namespace prefix xsl.

Having no namespace prefix.

Having no namespace prefix.

Write a Jdom application which generates statistical data like being represented by HTML to the right.

Your application is expected to operate on arbitrary XML input documents.

Providing suitable unit tests is an inherent part of this exercise!


You may obtain a collection of all nodes as a result of the XPath expression //*. Then construct a Map<String, Set<...>> having namespaces as keys and sets of element names among with frequencies as values. Mind an appropriate equals() definition!