<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I assume you mean line 568?<div><br></div><div>I'll add some comments inline and you can tell me if I'm following the logic right.</div><div><br><div><blockquote type="cite"><div><div><font size="-1"><br>
    </font><font size="-1">            } else if (atts.getURI(i) != null
      && atts.getURI(i).length() > 0) {<br>
                      // the localname and qName are the same, but there
      is a<br>
                      // Namspace URI. We need to figure out the
      namespace prefix.<br>
                      // this is an unusual condition. Currently the
      only known trigger<br>
                      // is when there is a fixed/defaulted attribute
      from a validating<br>
                      // XMLSchema, and the attribute is in a different
      namespace<br>
                      // than the rest of the document, this happens
      whenever there<br>
                      // is an attribute definition that has
      form="qualified".<br>
                      //  <xs:attribute name="attname"
      form="qualified" ... /><br>
                      // or the schema sets
      attributeFormDefault="qualified"<br></font></div></div></blockquote><div><br></div><div>// The goal of this searching code is to find a good attNS namespace we can use.</div><br><blockquote type="cite"><div><div><font size="-1">
                      String attURI = atts.getURI(i);<br>
                      Namespace attNS = null;<br>
                      Element p = element;<br>
                      // We need to ensure that a particular prefix has
      not been<br>
                      // overridden at a lower level than what we are
      expecting.<br>
                      // track all prefixes to ensure they are not
      changed lower<br>
                      // down.<br>
                      HashSet overrides = new HashSet();<br>
                      uploop: do {<br>
                          // Search up the Element tree looking for a
      prefixed namespace<br>
                          // matching our attURI<br></font></div></div></blockquote><div><br></div><div>// First look at the element itself</div><br><blockquote type="cite"><div><div><font size="-1">
                          if (p.getNamespace().getURI().equals(attURI)<br>
                                  &&
      !overrides.contains(p.getNamespacePrefix())<br>
                                  &&
      !"".equals(element.getNamespace().getPrefix())) {<br>
                              // we need a prefix. It's impossible to
      have a namespaced<br>
                              // attribute if there is no prefix for
      that attribute.<br>
                              attNS = p.getNamespace();<br>
                              break uploop;<br>
                          }<br></font></div></div></blockquote><div><br></div>// Then any additional namespaces defined on the element</div><div><br><blockquote type="cite"><div><div><font size="-1">
                          overrides.add(p.getNamespacePrefix());<br>
                          for (Iterator it =
      p.getAdditionalNamespaces().iterator(); <br>
                                  it.hasNext(); ) {<br>
                              Namespace ns = (Namespace)it.next();<br>
                              if (!overrides.contains(ns.getPrefix())<br>
                                       &&
      attURI.equals(ns.getURI())) {<br>
                                  attNS = ns;<br>
                                  break uploop;<br>
                              }<br>
                              overrides.add(ns.getPrefix());<br>
                          }<br></font></div></div></blockquote><div><br></div><div>// If we haven't hit something yet, keep walking up the tree</div><br><blockquote type="cite"><div><div><font size="-1">
                          if (p == element) {<br>
                              p = currentElement;<br>
                          } else {<br>
                              p = p.getParentElement();<br>
                          }<br>
                      } while (p != null);<br></font></div></div></blockquote><div><br></div><div>// If we still don't have attNS we need to invent a unique one</div><br><blockquote type="cite"><div><div><font size="-1">                if (attNS == null) {<br>
                          // we cannot find a 'prevailing' namespace
      that has a prefix<br>
                          // that is for this namespace.<br>
                          // This basically means that there's an
      XMLSchema, for the<br>
                          // DEFAULT namespace, and there's a
      defaulted/fixed<br>
                          // attribute definition in the XMLSchema
      that's targeted<br>
                          // for this namespace,... but, the user has
      either not<br>
                          // declared a prefixed version of the
      namespace, or has<br>
                          // re-declared the same prefix at a lower
      level with a<br>
                          // different namespace.<br>
                          // All of these things are possible.<br>
                          // Create some sort of default prefix.<br>
                          int cnt = 0;<br>
                          String base = "attns";<br>
                          String pfx = base + cnt;<br>
                          while (overrides.contains(pfx)) {<br>
                              cnt++;<br>
                              pfx = base + cnt;<br>
                          }<br>
                          attNS = Namespace.getNamespace(pfx, attURI);<br>
                      }<br></font></div></div></blockquote><div><br></div><div>Finally build the attribute, using either a found attNS or an invented one</div><br><blockquote type="cite"><div><div><font size="-1">
                      attribute = factory.attribute(attLocalName,
      atts.getValue(i),<br>
                              attType, attNS);<br>
                  } else {<br></font></div></div></blockquote></div><br></div><div>Lastly, DOMBuilder needs code like this too, no?</div><div><br></div><div>-jh-</div><div><br></div></body></html>