public function buildBodyXml($contents)
    {
        $this->contextDataType   = self::CONTENT_TYPE_XML;
        $this->contextDataExists = (bool) (strlen($contents) > 0);
        $this->contextDataValue  = simplexml_load_string($contents);

        if ($this->contextDataValue === false) {
            $this->contextDataEmpty   = true;
            $this->contextDataValue   = null;
            $this->contextDecodeError = array();

            foreach (libxml_get_errors() as $error) {
                $this->contextDecodeError[] = array('code' => $error->$code, 'message' => $error->message);
            }
        }
        else {
            $this->contextDataValue = \SwaggerValidator\Common\Collection::jsonEncode($this->getDataValue());

            if (json_last_error() !== JSON_ERROR_NONE) {
                $this->contextDataEmpty = true;
                $this->contextDataValue = null;
                if (function_exists('json_last_error_msg')) {
                    $this->contextDecodeError[] = array('code' => json_last_error(), 'message' => json_last_error_msg());
                }
                else {
                    $this->contextDecodeError[] = array('code' => json_last_error(), 'message' => null);
                }
            }
            else {
                $this->contextDataValue = json_decode($this->getDataValue(), false);

                if (json_last_error() !== JSON_ERROR_NONE) {
                    $this->contextDataEmpty = true;
                    $this->contextDataValue = null;
                    if (function_exists('json_last_error_msg')) {
                        $this->contextDecodeError[] = array('code' => json_last_error(), 'message' => json_last_error_msg());
                    }
                    else {
                        $this->contextDecodeError[] = array('code' => json_last_error(), 'message' => null);
                    }
                }
                else {
                    $this->checkDataIsEmpty();
                }
            }
        }
    }