0

我正在做一个项目,我正在以 xml 格式保存我的数据。我无法在我的数据中保存双引号。我尝试用 " 替换双引号,但它没有用。请建议如何实现这一点。

以下是我传递的 xml 数据

<question HasOptions="0" answer=""I think ki I am vulnerable"...text check // "i am afraid"" QuestionId="2042" OptionId="1260" ></question>

我用于创建 xml 的 javascript 代码

function GetXMLForPosting() {

        // here is the XML for posting

        var xmlqQuestionResponse = '<question HasOptions="{{hasOptions}}" answer="{{score}}" QuestionId="{{questionID}}" OptionId="{{optionID}}" />';
        var answers = '';
        //lopping through questions
        $('.little_text').each(function () {

            // question data
            hasOptions = $(this).attr('hasoptions');
            questionID = $(this).attr('questionid');

            // option data
            selectedOption = $(this).find('input[name=radio_' + questionID + ']:checked');
            score = $(selectedOption).attr('value');
            optionID = $(selectedOption).attr('id');

            // end
            if (questionID > 0) {

                if (hasOptions == 0) {
                    // case of textarea
                    // overiding default values
                    selectedOption = $(this).find('textarea[name=radio_' + questionID + ']');
                    score = $(selectedOption).val();
                    optionID = '1260';
                    answers = answers + xmlqQuestionResponse
                            .replace('{{hasOptions}}', hasOptions)
                            .replace('{{score}}', score.replace(/\'/g, "\'"))
                            .replace('{{questionID}}', questionID)
                            .replace('{{optionID}}', optionID);
                }
                else {
                    // normal radio button
                    answers = answers + xmlqQuestionResponse
                            .replace('{{hasOptions}}', hasOptions)
                            .replace('{{score}}', score)
                            .replace('{{questionID}}', questionID)
                            .replace('{{optionID}}', optionID);
                }

            }

        });

        //console.log('<questions>' + answers + '</questions>');
        return '<questions>' + answers + '</questions>';

    }

这里我的答案是得分选项

我的cs代码

[HttpPost]
    public ActionResult Postback(FormCollection formCollection)
    {
        // Process the take questionnaire
        var model = (WorkflowMessage)Session[Enumerations.SessionItems.ViewModel];

        // Check the page guid redirect accoringly
        if (!GuidValid())
            return ReshowPage();

        var rawData = formCollection[Enumerations.FlashVariableFormPostKey.OutputData];
        var enc = Encoding.GetEncoding("ISO-8859-1");
        var responseXml = HttpUtility.UrlDecode(rawData, enc);
        // redundant variable left so that at debug time the result can be inspected.
        var result = new QuestionnaireService().SaveTakenQuestionnaire(PatientSessionDataObject.TreatmentId, model.PatientId, PatientSessionDataObject.CustomerId, model.AssetData, rawData);

        return RedirectToAction("Next", "Treatment", new { navigationChosen = "Next", area = string.Empty, model.PageCheckGuid });
    }

请建议我如何保存文本-“我认为我很脆弱”...文本检查//“我害怕”在我的答案字段中。谢谢

4

1 回答 1

0

你需要使用&quot;.

以你的例子...

<question HasOptions="0" answer="&quot;I think ki I am vulnerable&quot;...text check // &quot;i am afraid&quot;" QuestionId="2042" OptionId="1260" ></question>
于 2015-05-01T12:24:32.297 回答