Code example for Node

Methods: getAttributes, getTextContent

0
	 
	public static ApiResponse getResponse(Node node) throws ClientApiException {
		if (node == null) {
			throw new ClientApiException("Null node"); 
		} 
		Node typeNode = node.getAttributes().getNamedItem("type");
		if (typeNode != null) {
			String type = typeNode.getNodeValue();
			if ("list".equals(type)) {
				return new ApiResponseList(node);
			} 
			if ("set".equals(type)) {
				return new ApiResponseSet(node);
			} 
			if ("exception".equals(type)) {
				NamedNodeMap atts = node.getAttributes();
 
				String code = atts.getNamedItem("code").getNodeValue();
				String detail = null;
				if (atts.getNamedItem("detail") != null) {
					detail = atts.getNamedItem("detail").getNodeValue();
				} 
				throw new ClientApiException(node.getTextContent(), code, detail); 
			} 
		} 
		return new ApiResponseElement(node);
	} 
 
}