protected function castValue(SimpleXMLElement $xmlElement)
    {
        $attributes = $xmlElement->attributes();
        if (isset($attributes['nil']) && $attributes['nil'] == 'true') {
            $value = null;
        } else {
            switch (isset($attributes['type']) ? strval($attributes['type']) : null) {
                case 'integer':
                    $value = intval($xmlElement);
                    break;
                case 'float':
                    $value = floatval($xmlElement);
                    break;
                case 'boolean':
                    $value = strval($xmlElement) == 'true';
                    break;
                case 'datetime':
                case 'date':
                    $value = new DateTime(strval($xmlElement));
                    break;
                case 'string':
                default:
                    $value = strval($xmlElement);
                    break;
            }
        }
        return $value;
    }