protected String extractAttribute ( String stringContainingAttributes , String attributeName ) { String attributeValue = "" ; stringContainingAttributes = stringContainingAttributes . replaceAll ( "<" , "" ) . replaceAll ( ">" , "" ) ; String [ ] keyValues = stringContainingAttributes . split ( " " ) ; for ( int i = 0 ; i < keyValues . length ; i ++ ) { String keyValue = keyValues [ i ] . trim ( ) ; String [ ] keyAndValue = keyValue . split ( "=" ) ; if ( keyAndValue [ 0 ] . equalsIgnoreCase ( attributeName ) ) { return keyAndValue [ 1 ] . substring ( 1 , keyAndValue [ 1 ] . length ( ) - 1 ) ; } } return attributeValue ; }
Given a String containing XML - like attributes and a key it extracts a value