void copyIdField ( Element readNode ) { String newId = readNode . getAttribute ( "data-semantic-id" ) ; if ( ! StringUtils . isEmpty ( newId ) ) { readNode . setAttribute ( "id" , "p" + newId ) ; } for ( Node child : new NonWhitespaceNodeList ( readNode . getChildNodes ( ) ) ) { if ( child instanceof Element ) { copyIdField ( ( Element ) child ) ; } } }
Copy the data - semantic - id attribute to id if it does not exist . Will recursively go over every child .