在xml中传递双打引号

时间:2015-05-01 12:18:05

标签: javascript c# xml xml-encoding

我正在开发一个项目,我以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 });
    }

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

1 个答案:

答案 0 :(得分: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>