Programming Tips - How can I get the XML version and encoding with the SAX parser?

Date: 2013oct22 Language: Java Q. How can I get the XML version and encoding with the SAX parser? A. Make setDocumentLocator() in your handler like this:
@Override public void setDocumentLocator(Locator locator) { if (locator instanceof Locator2) { Locator2 loc2 = (Locator2) locator; String ver = loc2.getXMLVersion(); String enc = loc2.getEncoding(); } }