protected function cast(\SimpleXMLElement $xml, $type = 'string')
    {
        switch ($type) {
            case 'string':
                return (string) $xml;
            case 'int':
                return (int) $xml;
            case 'double':
                return (double) $xml;
            case 'boolean' :
                return (bool) ((string) $xml);
            case 'datetime':
                $date = (string) $xml;
                if (empty($date)) {
                    return null;
                }
                return new \DateTime($date);
            default:
                return $xml;
        }
    }