我有一个控制器,它以这种格式从外部支付门户获取数据:
状态=%3CportalRes +的xmlns%3D%22http%3A%2F%2Fwww.e-paycapita.com%2Fportal%22%3E%3CrequestID%3E7%3C%2FrequestID%3E%3CreqStatus%3E%3CstatusCode%3E0% 3C%2FstatusCode%3E%3Cmessage%3EPayment + - +塞尔+ - +处理+完成+成功%3C%2Fmessage%3E%3C%2FreqStatus%3E%3CauthDetail%3E%3CresponseCode%3E00%3C%2FresponseCode%3E%3Cmessage%3E %26quot%3BAUTH + CODE%3A100955%26quot%3B%3C%2Fmessage%3E%3CauthCode%3E100955%3C%2FauthCode%3E%3Camount%3E10000%3C%2Famount%3E%3Ccan%3E2506%3C%2Fcan%3E%3C %2FauthDetail%3E%3Csurcharge%3E%3CfundCode%3ECSRCH%3C%2FfundCode%3E%3Creference%3EA15009581%3C%2Freference%3E%3Camount%3E175%3C%2Famount%3E%3C%2Fsurcharge%3E%3Cmop%3E51%3C %2Fmop%3E%3Ccart%3E%3Citems%3E%3Citem%3E%3Creference%3EA7000%3C%2Freference%3E%3Creference2%3E1234%3C%2Freference2%3E%3Ccan%3E2506%3C%2Fcan%3E%3CfundCode%3E8 %3C%2FfundCode%3E%3Camount%3E10000%3C%2Famount%3E%3C%2Fitem%3E%3C%2Fitems%3E%3C%2Fcart%3E%3C%2FportalRes%3E
如何将其转换为C#中的XmlDocument
对象?
答案 0 :(得分:2)
如果状态包含字符串:
var xml = new XmlDocument();
xml.LoadXml(HttpUtility.UrlDecode(status));
数据(状态)是这样的:
<portalRes xmlns="http://www.e-paycapita.com/portal">
<requestID>7</requestID>
<reqStatus>
<statusCode>0</statusCode>
<message>Payment - Sale - Processing completed successfully.</message>
</reqStatus>
<authDetail>
<responseCode>00</responseCode>
<message>"AUTH CODE:100955"</message>
<authCode>100955</authCode>
<amount>10000</amount>
<can>2506</can>
</authDetail>
<surcharge>
<fundCode>CSRCH</fundCode>
<reference>A15009581</reference>
<amount>175</amount>
</surcharge>
<mop>51</mop>
<cart>
<items>
<item>
<reference>A7000</reference>
<reference2>1234</reference2>
<can>2506</can>
<fundCode>8</fundCode>
<amount>10000</amount>
</item>
</items>
</cart>
答案 1 :(得分:1)
您需要调用Server.UrlDecode
,然后解析xml内容。
答案 2 :(得分:1)
只需在引用中包含System.Web
(如果尚未包含),然后使用HttpUtility.UrlDecode方法。
var result = HttpUtility.UrlDecode(input);