0

HTMLフォームをサードパーティのWebサイトに送信する必要がありますが、非表示のフィールドの1つはXML文字列です。XMLは、サードパーティに送信される前にエスケープする必要があります。

ただし、プレーンXMLをフォームフィールドに追加すると、セミエスケープされます。したがって、HTMLEncodeを自分で使用すると、XMLの一部が二重にエスケープされます。.NETからのように見える自動エスケープを防ぐにはどうすればよいですか。

または、他の方法で、エスケープされたXMLを非表示フィールドを介して送信する方法もあります。

XML

<systemCode>APP</systemCode>

非表示の入力フィールドへの基本的な割り当て

&lt;systemCode>APP&lt;/systemCode>

HTMLでエンコードするときも

&amp;lt;systemCode&amp;gt;APP&amp;lt;/systemCode&amp;gt;

何が起こっているのかはわかりますが、それを防ぐ方法がわかりません。

4

3 に答える 3

4

HTMLEncode も使用しないでください一人で使おう!

何かのようなもの:

'Setting value:
hdnField.Value = Server.HtmlEncode("<systemCode>APP</systemCode>")
'Outputs: &amp;lt;systemCode&amp;gt;APP&amp;lt;/systemCode&amp;gt;

'Retrieving encoded value:
Dim escaped as string = Request.Form("hdnField")
'Retrieves: &lt;systemCode&gt;APP&lt;/systemCode&gt;

'Retrieving decoded value:
Dim myValue As String = Server.HtmlDecode(Request.Form("hdnField"))
'Retrieves: "<systemCode>APP</systemCode>"
于 2009-05-06T09:54:17.053 に答える
0

You don't need to worry about the HTML output. Only worry about what data is submitted in the form. It doesn't matter whether the HTML is fully escaped or partially escaped - the same data gets submitted either way.

Both of these fields:

<input name="xml" value="&lt;systemCode>APP&lt;/systemCode>" />
<input name="xml" value="&lt;systemCode&gt;APP&lt;/systemCode&gt;" />

Get submitted as:

xml=%3CsystemCode%3EAPP%3C%2FsystemCode%3E

This is language agnostic - it is browser behavior. When the browser parses the HTML, it will actually normalize both fields to have the same html. If you view source of the page, you will see that the source HTML differs between the inputs, but if you read the form.innerHTML value, you'll see that the parsed HTML is identical.

Demo:
http://jsfiddle.net/gilly3/Xdj5E/

于 2012-06-08T17:57:33.823 に答える
0

最後に、リテラルを使用してから、XML文字列をHTMLEncodingしてから、リテラルテキストフィールドにHTMLフォーム変数を割り当てました。以下のように少し:

portalReq.Text = "<input type=""hidden"" name=""portalReq"" value='" & HTMLENCODE(RequestXML) & "' />"

エレガントではありませんが、問題を回避しています。

于 2009-05-19T07:58:04.963 に答える