class OpenStackParser {

    public String[][] parseNetworkCollectionResponse (String response)
    		                                             throws OCCIException {
        String[][] ret = null;
        List idList, nameList, subnetList;
        XPath xpath;
        SAXBuilder builder = new SAXBuilder();
        builder.setValidation(false);
        builder.setIgnoringElementContentWhitespace(true);
        Document xmldoc;
        
        log.info("[OpenStackParser] Parsing network collection response...");
        try {
            xmldoc = builder.build(new StringReader(response));
            xpath = XPath.newInstance("//ns:network/ns:id");
            xpath.addNamespace("ns", QUANTUMNAMESPACE);
            xpath.addNamespace("provider", PROVIDERNAMESPACE);
            xpath.addNamespace("quantum", QUANTUMNAMESPACE);
            xpath.addNamespace("router", ROUTERNAMESPACE);
            xpath.addNamespace("xsi", XSINAMESPACE);
            idList = xpath.selectNodes(xmldoc);
            
            xpath = XPath.newInstance("//ns:network/ns:name");
            xpath.addNamespace("ns", QUANTUMNAMESPACE);
            xpath.addNamespace("provider", PROVIDERNAMESPACE);
            xpath.addNamespace("quantum", QUANTUMNAMESPACE);
            xpath.addNamespace("router", ROUTERNAMESPACE);
            xpath.addNamespace("xsi", XSINAMESPACE);
            nameList = xpath.selectNodes(xmldoc);
            
            ret = new String[idList.size()][];
            if (idList.size() == nameList.size()) {
	            for (int i = 0; i < idList.size(); i++) {
	                String id = ((Element)idList.get(i)).getValue();
	                
	                xpath =
	                    XPath.newInstance("//ns:network[ns:id=\"" +
	                                      id + "\"]/*/ns:subnet");
	                xpath.addNamespace("ns", QUANTUMNAMESPACE);
	                xpath.addNamespace("provider", PROVIDERNAMESPACE);
	                xpath.addNamespace("quantum", QUANTUMNAMESPACE);
	                xpath.addNamespace("router", ROUTERNAMESPACE);
	                xpath.addNamespace("xsi", XSINAMESPACE);
	                subnetList = xpath.selectNodes(xmldoc);
	                
	                ret[i] = new String[subnetList.size() + 2];
	                
	                ret[i][0] = id;
	                ret[i][1] = ((Element)nameList.get(i)).getValue();
	                
	                for (int j = 0; j < subnetList.size(); j++) {
	                    ret[i][j+2] = ((Element)subnetList.get(j)).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] Network collection response parsed...");
        
        return ret;
    }

}