class OpenStackParser {

    public NetworkCollection parseSubnetCollectionResponse (String response)
                                                         throws OCCIException {
        Link link;
        ArrayList<Link> links;
        NetworkCollection ret = null;
        SAXBuilder builder = new SAXBuilder();
        builder.setValidation(false);
        builder.setIgnoringElementContentWhitespace(true);
        Document xmldoc;
        
        log.info("[OpenStackParser] Parsing subnet collection response...");
        try {
            xmldoc = builder.build(new StringReader(response));
            XPath xpath = XPath.newInstance("//ns:subnet/ns:id");
            xpath.addNamespace("ns", QUANTUMNAMESPACE);
            xpath.addNamespace("quantum", QUANTUMNAMESPACE);
            xpath.addNamespace("xsi", XSINAMESPACE);
            List idList = xpath.selectNodes(xmldoc);
            
            xpath = XPath.newInstance("//ns:subnet/ns:name");
            xpath.addNamespace("ns", QUANTUMNAMESPACE);
            xpath.addNamespace("quantum", QUANTUMNAMESPACE);
            xpath.addNamespace("xsi", XSINAMESPACE);
            List nameList = xpath.selectNodes(xmldoc);
            
            if (idList.size() == nameList.size()) {
                links = new ArrayList<Link>();
                ret = new NetworkCollection();
                Iterator idIt = idList.iterator();
                Iterator nameIt = nameList.iterator();
                
                while (idIt.hasNext()) {
                    link = new Link();
                    link.setHref(((Element)idIt.next()).getValue());
                    link.setName(((Element)nameIt.next()).getValue());
                    
                    links.add(link);
                }
                ret = new NetworkCollection();
                ret.getNetwork().addAll(links);
            } 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 collection response parsed...");
        
        return ret;
    }

}