class OpenStackParser {

    public Network parseSubnetResponse (String response)
                                                       throws OCCIException {
        Network ret = null;
        Element href, address, name;
        String size;
        SAXBuilder builder = new SAXBuilder();
        builder.setValidation(false);
        builder.setIgnoringElementContentWhitespace(true);
        Document xmldoc;
        int netClass;
        
        log.info("[OpenStackParser] Parsing subnet response...");
        try {
            ret = new Network();
            
            xmldoc = builder.build(new StringReader(response));
            XPath xpath = XPath.newInstance("//ns:id");
            xpath.addNamespace("ns", QUANTUMNAMESPACE);
            xpath.addNamespace("quantum", QUANTUMNAMESPACE);
            xpath.addNamespace("xsi", XSINAMESPACE);
            href = (Element)xpath.selectSingleNode(xmldoc);
            
            xpath = XPath.newInstance("//ns:cidr");
            xpath.addNamespace("ns", QUANTUMNAMESPACE);
            xpath.addNamespace("quantum", QUANTUMNAMESPACE);
            xpath.addNamespace("xsi", XSINAMESPACE);
            address = (Element)xpath.selectSingleNode(xmldoc);
            
            xpath = XPath.newInstance("//ns:name");
            xpath.addNamespace("ns", QUANTUMNAMESPACE);
            xpath.addNamespace("quantum", QUANTUMNAMESPACE);
            xpath.addNamespace("xsi", XSINAMESPACE);
            name = (Element)xpath.selectSingleNode(xmldoc);
            
            if (href != null && address != null && name != null) {
            	ret.setAddress(address.getValue());
            	ret.setHref(href.getValue());
            	ret.setName(name.getValue());
            	
            	netClass = Integer.parseInt(ret.getAddress().split("\\.")[0]);
                size     = null;
                if (netClass < 128) {
                	size = "A";
                } else if (netClass < 192) {
                	size = "B";
                } else if (netClass < 224) {
                	size = "C";
                } else if (netClass < 240) {
                	size = "D";
                } else if (netClass < 256) {
                	size = "E";
                } else {
                	OCCIException exception = new OCCIException();
                    exception.setMessage(BADADDRESS);
                    log.error(BADADDRESS);
                    throw exception;
                }
            	
            	ret.setSize(size);
            } 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] Subnet response parsed...");
        
        return ret;
    }

}