That is a "feature" of the current implementation. The resulting XML file is equivalent to what you expect but I agree that it would be nice to not have the duplicated namespaces. We do have plans to rework many of the builders in light of JDK8 streams, so we haven't invested in trying to make the existing implementation nicer in that regard. The current implementation makes it harder than you might think to fix but we'd happily accept PRs.

Cheers, Paul.

On Tue, Sep 24, 2019 at 1:13 PM Nelson, Erick <Erick.Nelson@hdsupply.com> wrote:

This Code…

 

import groovy.xml.*

 

StreamingMarkupBuilder smb = new StreamingMarkupBuilder()

smb.encoding = 'UTF-8'

 

def doc = smb.bind {

    mkp.declareNamespace('':'http://www.sitemaps.org/schemas/sitemap/0.9')

    urlset {

        url {

            loc(1)

            lastmod('2019-09-21')

            changefreq('daily')

            priority('1')

            one('b')

            two('a')

            three('c')

            four('d')

            five('e')

            six('f')

            seven('g')

        }

    }

}

 

println XmlUtil.serialize(doc)

 

 

Produces this xml …

 

<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  <url>

    <loc>1</loc>

    <lastmod xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">2019-09-21</lastmod>

    <changefreq>daily</changefreq>

    <priority>1</priority>

    <one xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">b</one>

    <two>a</two>

    <three>c</three>

    <four xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">d</four>

    <five>e</five>

    <six>f</six>

    <seven xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">g</seven>

  </url>

</urlset>

 

But I was expecting …

 

<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  <url>

    <loc>1</loc>

    <lastmod>2019-09-21</lastmod>

    <changefreq>daily</changefreq>

    <priority>1</priority>

    <one>b</one>

    <two>a</two>

    <three>c</three>

    <four>d</four>

    <five>e</five>

    <six>f</six>

    <seven>g</seven>

  </url>

</urlset>

 

Why am I getting all the extra xmlns attributes? Seems like every 3 nodes has the namespace.

 

 

Nelson, Erick