protected function getLiteralValue($element)
    {
        $value = $element->getValue();
        $trimmed_value = trim($value);

        $preserve_whitespace = $element->getAttributeValue('space', 'default') === 'preserve';
        $literalize_value = self::literalize($element->getAttributeValue('literalize')) !== false;

        if ($literalize_value) {
            if ($preserve_whitespace && ($trimmed_value === '' || $value !== $trimmed_value)) {
                $value = $value;
            } else {
                $value = self::literalize($trimmed_value);
            }
        } elseif (!$preserve_whitespace) {
            $value = $trimmed_value;
            if ($value === '') {
                $value = null;
            }
        }

        return $value;
    }