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;
        }
    }
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;
        }
    }
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 ; } }
casts a simple xml element to a type

@param        $xml
@param string $type

@return float|int|null|string|\DateTime
casts a simple xml element to a type