private static void calculateNamespaces(Map<String,XmlNamespace> namespaces,Element e,ElementMetadata<?,?> metadata){
  QName name=(metadata == null) ? e.getElementId() : metadata.getName();
  addNamespace(namespaces,name);
  Iterator<Attribute> attIter=e.getAttributeIterator(metadata);
  while (attIter.hasNext()) {
    Attribute att=attIter.next();
    AttributeKey<?> attKey=att.getAttributeKey();
    AttributeMetadata<?> attMeta=(metadata == null) ? null : metadata.bindAttribute(attKey);
    name=(attMeta == null) ? attKey.getId() : attMeta.getName();
    addNamespace(namespaces,name);
  }
  Iterator<Element> childIter=e.getElementIterator(metadata);
  while (childIter.hasNext()) {
    Element child=childIter.next();
    ElementMetadata<?,?> childMeta=(metadata == null) ? null : metadata.bindElement(child.getElementKey());
    calculateNamespaces(namespaces,child,childMeta);
  }
}

private static void calculateNamespaces ( Map < String , XmlNamespace > namespaces , Element e , ElementMetadata < ? , ? > metadata ) { QName name = ( metadata == null ) ? e . getElementId ( ) : metadata . getName ( ) ; addNamespace ( namespaces , name ) ; Iterator < Attribute > attIter = e . getAttributeIterator ( metadata ) ; while ( attIter . hasNext ( ) ) { Attribute att = attIter . next ( ) ; AttributeKey < ? > attKey = att . getAttributeKey ( ) ; AttributeMetadata < ? > attMeta = ( metadata == null ) ? null : metadata . bindAttribute ( attKey ) ; name = ( attMeta == null ) ? attKey . getId ( ) : attMeta . getName ( ) ; addNamespace ( namespaces , name ) ; } Iterator < Element > childIter = e . getElementIterator ( metadata ) ; while ( childIter . hasNext ( ) ) { Element child = childIter . next ( ) ; ElementMetadata < ? , ? > childMeta = ( metadata == null ) ? null : metadata . bindElement ( child . getElementKey ( ) ) ; calculateNamespaces ( namespaces , child , childMeta ) ; } }
calculate the namespaces on an element using the given visitor to store the namespaces . we cheat by using an attribute visitor for even visiting the element names , because all we ' re doing with the visitor is adding a qname .
