String prefix;
final NamedNodeMap map = node.getAttributes();
final int length = map.getLength();
// Process all other attributes
NamespaceMappings nm = new NamespaceMappings();
for (int i = 0; i < length; i++) {
int colon;
final Node attr = map.item(i);
final String qnameAttr = attr.getNodeName();
if (qnameAttr.startsWith(XMLNS_PREFIX)) {
final String uriAttr = attr.getNodeValue();
colon = qnameAttr.lastIndexOf(':');
prefix = (colon > 0) ? qnameAttr.substring(colon + 1)
: EMPTYSTRING;
_handler.namespaceAfterStartElement(prefix, uriAttr);
}
else {
final String uriAttr = attr.getNamespaceURI();
// Uri may be implicitly declared
if (uriAttr != null && !uriAttr.equals(EMPTYSTRING) ) {
colon = qnameAttr.lastIndexOf(':');
// Fix for bug 26319
// For attributes not given an prefix explictly
// but having a namespace uri we need
// to explicitly generate the prefix
String newPrefix = nm.lookupPrefix(uriAttr);
if (newPrefix == null)
newPrefix = nm.generateNextPrefix();
prefix = (colon > 0) ? qnameAttr.substring(0, colon)
: newPrefix;
_handler.namespaceAfterStartElement(prefix, uriAttr);
_handler.addAttribute((prefix + ":" + qnameAttr)
, attr.getNodeValue());