protected TreeNode convert ( TreeNode parent , Node node ) { // Construct a new TreeNode for this node TreeNode treeNode = new TreeNode ( node . getNodeName ( ) , parent ) ; // Convert all attributes of this node NamedNodeMap attributes = node . getAttributes ( ) ; if ( attributes != null ) { int n = attributes . getLength ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Node attribute = attributes . item ( i ) ; treeNode . addAttribute ( attribute . getNodeName ( ) , attribute . getNodeValue ( ) ) ; } } // Create and attach all children of this node NodeList children = node . getChildNodes ( ) ; if ( children != null ) { int n = children . getLength ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Node child = children . item ( i ) ; if ( child instanceof Comment ) continue ; if ( child instanceof Text ) { String body = ( ( Text ) child ) . getData ( ) ; if ( body != null ) { body = body . trim ( ) ; if ( body . length ( ) > 0 ) treeNode . setBody ( body ) ; } } else { TreeNode treeChild = convert ( treeNode , child ) ; } } } // Return the completed TreeNode graph return ( treeNode ) ; }
Create and return a TreeNode that corresponds to the specified Node including processing all of the attributes and children nodes .