anchor.diff:      if (prefix == _XMLNS || prefix == _XML) {
         throw new ArgumentError('The "$prefix" prefix cannot be bound.');
       }
  -    if (_stack.any((builder) => builder.namespaces[uri] != null && builder.namespaces[uri].prefix == prefix)) {
  -      // namespace prefix already correctly specified
  +    if (optimizeNamespaces && _stack.any(
  +        (builder) => builder.namespaces.containsKey(uri) &&
  +                     builder.namespaces[uri].prefix == prefix)) {
  +      // namespace prefix already correctly specified in an ancestor
         return;
       }
       if (_stack.last.namespaces.values.any((meta) => meta.prefix == prefix)) {
  
positive.code: 
    // Internal method to build a name.
    XmlName _buildName(String name, String uri) {
      return uri == null || uri.isEmpty
          ? new XmlName.fromString(name)
          : new XmlName(name, _lookup(uri).prefix);
    }
  
    // Internal method to lookup an namespace prefix.
  
negative.code:  * A builder to create XML trees with code.
   */
  class XmlBuilder {
  
    /**
     * If [optimizeNamespaces] is true, the builder will perform
     * namespace optimization.
     *
     * This means that
     *  - namespaces that are defined in an element but are never used in this
     *    element or its children will not be included in the document;
     *  - namespaces that are defined in an element but are already defined in
     *    one of the ancestors of the element will not be included again.
     */
    final bool optimizeNamespaces;
  
    final List<_XmlNodeBuilder> _stack =
        new List.from([new _XmlDocumentBuilder()]);
  
    /**
     * Construct a new [XmlBuilder].
     *
     * For the meaning of the [optimizeNamespaces] parameter, read the
     * documentation of the [optimizeNamespaces] property.
     */
    XmlBuilder({this.optimizeNamespaces: false});
  
    /**
     * Adds a [XmlText] node with the provided [text].
  