class OpenStackParser {

    public InstanceType parseInstanceTypeResponse (String response) 
                                                        throws OCCIException {
    	Attribute vcpu, ram, name, id;
        InstanceType ret = new InstanceType();
        SAXBuilder builder = new SAXBuilder();
        builder.setValidation(false);
        builder.setIgnoringElementContentWhitespace(true);
        Document xmldoc;
        
        log.info("[OpenStackParser] Parsing instance type response...");
        try {
            xmldoc = builder.build(new StringReader(response));
            XPath xpath = XPath.newInstance("//ns:flavor/@vcpus");
            xpath.addNamespace("ns", KEYSTONENAMESPACE);
            vcpu = (Attribute) xpath.selectSingleNode(xmldoc);
            
            xpath = XPath.newInstance("//ns:flavor/@ram");
            xpath.addNamespace("ns", KEYSTONENAMESPACE);
            ram = (Attribute) xpath.selectSingleNode(xmldoc);
            
            xpath = XPath.newInstance("//ns:flavor/@name");
            xpath.addNamespace("ns", KEYSTONENAMESPACE);
            name = (Attribute) xpath.selectSingleNode(xmldoc);
            
            xpath = XPath.newInstance("//ns:flavor/@id");
            xpath.addNamespace("ns", KEYSTONENAMESPACE);
            id = (Attribute) xpath.selectSingleNode(xmldoc);
            
            if (vcpu != null && ram != null && name!= null && id != null) {
            	ret.setCpu(Integer.parseInt(vcpu.getValue()));
                ret.setHref(id.getValue());
                ret.setMemory(Integer.parseInt(ram.getValue()));
                ret.setName(name.getValue());
            } else {
            	OCCIException exception = new OCCIException();
                exception.setMessage(MALFORMEDRESPONSE);
                log.error(MALFORMEDRESPONSE);
                throw exception;
            }
        } catch (JDOMException e) {
            log.error(e.getMessage());
        } catch (IOException e) {
            log.error(e.getMessage());
        }
        log.debug("[OpenStackParser] Instance type response parsed...");
        
        return ret;
    }

}