anchor.diff:        var expected = '<foo:element xmlns:foo="http://1.foo.com/" />';
         expect(actual, expected);
       });
  +    test('conflicting namespace optimized', () {
  +      var builder = new XmlBuilder(optimizeNamespaces: true);
  +      builder.element('element', nest: () {
  +        builder.namespace('http://1.foo.com/', 'foo');
  +        expect(() => builder.namespace('http://2.foo.com/', 'foo'),
  +            throwsArgumentError);
  +      }, namespace: 'http://1.foo.com/');
  +      var actual = builder.build().toString();
  +      var expected = '<foo:element xmlns:foo="http://1.foo.com/" />';
  +      expect(actual, expected);
  +    });
  +    test('unused namespace', () {
  +      var builder = new XmlBuilder(optimizeNamespaces: false);
  +      builder.element('element', nest: () {
  +        builder.namespace('http://1.foo.com/', 'foo');
  +      });
  +      var actual = builder.build().toString();
  +      var expected = '<element xmlns:foo="http://1.foo.com/" />';
  +      expect(actual, expected);
  +    });
  +    test('unused namespace optimized', () {
  +      var builder = new XmlBuilder(optimizeNamespaces: true);
  +      builder.element('element', nest: () {
  +        builder.namespace('http://1.foo.com/', 'foo');
  +      });
  +      var actual = builder.build().toString();
  +      var expected = '<element />';
  +      expect(actual, expected);
  +    });
  +    test('duplicate namespace', () {
  +      var builder = new XmlBuilder(optimizeNamespaces: false);
  +      builder.element('element', nest: () {
  +        builder.namespace('http://1.foo.com/', 'foo');
  +        builder.element('inner', nest: () {
  +          builder.namespace('http://1.foo.com/', 'foo');
  +          builder.element('innerinner', nest: () {
  +            builder.namespace('http://1.foo.com/', 'foo');
  +            builder.attribute('lang', 'en', namespace: 'http://1.foo.com/');
  +          });
  +        });
  +      });
  +      var actual = builder.build().toString();
  +      var expected = '<element xmlns:foo="http://1.foo.com/">'
  +          '<inner xmlns:foo="http://1.foo.com/">'
  +          '<innerinner xmlns:foo="http://1.foo.com/" foo:lang="en" />'
  +          '</inner>'
  +          '</element>';
  +      expect(actual, expected);
  +    });
  +    test('duplicate namespace optimized', () {
  +      var builder = new XmlBuilder(optimizeNamespaces: true);
  +      builder.element('element', nest: () {
  +        builder.namespace('http://1.foo.com/', 'foo');
  +        builder.element('inner', nest: () {
  +          builder.namespace('http://1.foo.com/', 'foo');
  +          builder.element('innerinner', nest: () {
  +            builder.namespace('http://1.foo.com/', 'foo');
  +            builder.attribute('lang', 'en', namespace: 'http://1.foo.com/');
  +          });
  +        });
  +      });
  +      var actual = builder.build().toString();
  +      var expected = '<element xmlns:foo="http://1.foo.com/">'
  +          '<inner>'
  +          '<innerinner foo:lang="en" />'
  +          '</inner>'
  +          '</element>';
  +      expect(actual, expected);
  +    });
     });
     group('examples', () {
       test('books', () {
  
positive.code:       var expected = '<element />';
        expect(actual, expected);
      });
      test('conflicting namespace', () {
        var builder = new XmlBuilder();
        builder.element('element', nest: () {
          builder.namespace('http://1.foo.com/', 'foo');
          expect(() => builder.namespace('http://2.foo.com/', 'foo'),
  
negative.code:     });
      test('namespace binding', () {
        var uri = 'http://www.w3.org/2001/XMLSchema';
        var builder = new XmlBuilder(optimizeNamespaces: false);
        builder.element('schema', nest: () {
          builder.namespace(uri, 'xsd');
          builder.attribute('lang', 'en', namespace: uri);
  