// And finally, need to output attributes as well:
@SuppressWarnings("unchecked")
Iterator<Attribute> ait = elem.getAttributes();
while (ait.hasNext()) {
Attribute attr = ait.next();
name = attr.getName();
nsURI = name.getNamespaceURI();
// In non-default/empty namespace?
if (nsURI != null && nsURI.length() > 0) {
writeAttribute(name.getPrefix(), nsURI,
name.getLocalPart(), attr.getValue());
} else {
writeAttribute(name.getLocalPart(), attr.getValue());
}
}
}