code: public static String extractXmlEncoding(String content) {
  
          String result = null;
          Matcher xmlHeadMatcher = XML_HEAD_REGEX.matcher(content);
          if (xmlHeadMatcher.find()) {
              String xmlHead = xmlHeadMatcher.group();
              Matcher encodingMatcher = XML_ENCODING_REGEX.matcher(xmlHead);
              if (encodingMatcher.find()) {
                  String encoding = encodingMatcher.group();
                  int pos1 = encoding.indexOf('=') + 2;
                  String charset = encoding.substring(pos1, encoding.length() - 1);
                  if (Charset.isSupported(charset)) {
                      result = charset;
                  }
              }
          }
          return result;
      }
docs: Extracts the xml encoding setting from an xml file that is contained in a String by parsing
  the xml head.<p>
  
  This is useful if you have a byte array that contains a xml String,
  but you do not know the xml encoding setting. Since the encoding setting
  in the xml head is usually encoded with standard US-ASCII, you usually
  just create a String of the byte array without encoding setting,
  and use this method to find the 'true' encoding. Then create a String
  of the byte array again, this time using the found encoding.<p>
  
  This method will return <code>null</code> in case no xml head
  or encoding information is contained in the input.<p>
  
  @param content the xml content to extract the encoding from
  
  @return the extracted encoding, or null if no xml encoding setting was found in the input