class VersionFinder {

    public static String findVersion(Document doc) {
        String foundVersion = WMService.WMS_1_1_1;
        Node simpleXPath = XMLTools.simpleXPath(doc, "WMT_MS_Capabilities");
        if (simpleXPath != null) {
            NamedNodeMap attributes = simpleXPath.getAttributes();
            Node namedItem = attributes.getNamedItem("version");
            if (WMService.WMS_1_1_1.equals(namedItem.getNodeValue())
                    || WMService.WMS_1_1_0.equals(namedItem.getNodeValue())) {
                foundVersion = WMService.WMS_1_1_1;
            } else {
                foundVersion = WMService.WMS_1_0_0;
            }
        }
        simpleXPath = XMLTools.simpleXPath(doc, "WMS_Capabilities");
        if (simpleXPath != null) {
            NamedNodeMap attributes = simpleXPath.getAttributes();
            Node namedItem = attributes.getNamedItem("version");
            if (WMService.WMS_1_3_0.equals(namedItem.getNodeValue())) {
                foundVersion = WMService.WMS_1_3_0;
            }
        }
        return foundVersion;
    }

    public  VersionFinder();

}