code: private void scanFolderLevel( Element element, CMFolder cmFolder )
      {
          NodeList nodeList = element.getChildNodes();
  
          for ( int i = 0; i < nodeList.getLength(); i++ ) {
              Node currentNode = nodeList.item( i );
  
              if ( currentNode.getNodeType() != Node.ELEMENT_NODE ) {
                  continue;
              }
  
              Element currentElement = ( Element ) currentNode;
  
              if ( !currentElement.getLocalName().equals( "folder" ) ) {
                  continue;
              }
  
              //calls this method for all the children which is Element
              CMFolder childFolder = cmFolder.addChild( currentElement.getAttribute( "id" ),
                                                        currentElement.getAttribute( "name" ) );
  
              scanFolderLevel( currentElement, childFolder );
          }
      }
docs: Recursive method that parses folders XML and builds CMFolder structure.
  
  @param element
  @param cmFolder