import java.util.Iterator ;
import org.dom4j.Document ;
import org.dom4j.DocumentException ;
import org.dom4j.Element ;
import org.dom4j.io.SAXReader ;
public class ReadContacts {
  public static Document readContacts ( final String filename ) {
    try { return ( new SAXReader ( ) ).read ( filename ) ; }
    catch ( DocumentException de ) { de.printStackTrace ( ) ; System.exit ( 1 ) ; }
    return null ;
  }
  public static String stringify ( final Document document ) {
    final StringBuilder sb = new StringBuilder ( ) ;
    final Iterator<Element> contact = document.getRootElement ( ).elementIterator ( ) ;
    while ( contact.hasNext ( ) ) {
      final Iterator<Element> field = contact.next ( ).elementIterator ( ) ;
      while ( field.hasNext ( ) ) {
        final Element entry = field.next ( ) ;
        sb.append ( entry.getQualifiedName ( ) + " :  " + entry.getTextTrim ( ) + "\n" ) ;
      }
    }
    return sb.toString ( ) ;
  }
  public static void main ( final String[] args ) {
    System.out.println ( stringify ( readContacts ( "contacts.xml" ) ) ) ;
  }
}

