I am parsing XML using DocumentBuilder
in java 1.4.
XML has first line as
xml version=\"1.0\" encoding=\"GBK\"
I want to
One way to this works like this
final XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().createXMLStreamReader( new FileReader( testFile ) );
//running on MS Windows fileEncoding is "CP1251"
String fileEncoding = xmlStreamReader.getEncoding();
//the XML declares UTF-8 so encodingFromXMLDeclaration is "UTF-8"
String encodingFromXMLDeclaration = xmlStreamReader.getCharacterEncodingScheme();