public static String getEncoding ( String xmlStr ) { String result ; String xml = xmlStr . trim ( ) ; if ( xml . startsWith ( "<?xml" ) ) { int end = xml . indexOf ( "?>" ) ; int encIndex = xml . indexOf ( "encoding=" ) ; if ( encIndex != - 1 ) { String sub = xml . substring ( encIndex + 9 , end ) ; result = CommUtil . substringBetween ( sub , "\"" , "\"" ) ; return result ; } } return null ; }
Obtain xml file encoding attribute