重工电子论坛

标题: XML操作 [打印本页]

作者: 李维强-15级    时间: 2017-8-27 15:51
标题: XML操作
http://www.cnblogs.com/shenzhoul ... /01/27/1946532.html

http://www.cnblogs.com/xiaofeixiang/p/4067791.html
其实只要一个XMLElement就可以了
作者: 李维强-15级    时间: 2017-11-16 12:05
本帖最后由 李维强-15级 于 2017-11-17 22:34 编辑

由于微信支付通知的内容是XML的类似如下格式,所以需要相关的东西去解析
[C#] syntaxhighlighter_viewsource syntaxhighlighter_copycode

微信付款通知返回如下信息
<xml>
<appid><![CDATA[wx8261af4dcdbe9479]]></appid>
<attach><![CDATA[1490084]]></attach>
<bank_type><![CDATA[CFT]]></bank_type>
<cash_fee><![CDATA[100]]></cash_fee>
<fee_type><![CDATA[CNY]]></fee_type>
<is_subscribe><![CDATA[Y]]></is_subscribe>
<mch_id><![CDATA[1484638802]]></mch_id>
<nonce_str><![CDATA[dd68a90525824a5eae328a344aad1878]]></nonce_str>
<openid><![CDATA[ootlZwda9ehK2ypgSbrR7PTF6vug]]></openid>
<out_trade_no><![CDATA[148463880220171117222137687]]></out_trade_no>
<result_code><![CDATA[SUCCESS]]></result_code>
<return_code><![CDATA[SUCCESS]]></return_code>
<sign><![CDATA[CEFCB4A2D9EDD9400DD6146AE5545996]]></sign>
<time_end><![CDATA[20171117222206]]></time_end>
<total_fee>100</total_fee>
<trade_type><![CDATA[JSAPI]]></trade_type>
<transaction_id><![CDATA[4200000024201711175331618958]]></transaction_id>
</xml>



下面给一个示例,做到读取相关内容

[C#] syntaxhighlighter_viewsource syntaxhighlighter_copycode
private int ReadXml()
        {
            string responseInfo = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
                                + @"<xml>
                                        <appid>
                                            <![CDATA[wx8888888888888888]]>
                                        </appid>
                                    </xml>";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(responseInfo);
            string xpathChiefComplaint = "/xml/appid";

            XmlNode xnChiefComplaint = doc.SelectSingleNode(xpathChiefComplaint);

            string nodeValue = xnChiefComplaint.InnerText;
        }

以上代码的 nodeValue就是wx8888888888888888




欢迎光临 重工电子论坛 (http://www.cqutlab.cn/) Powered by Discuz! X3.1