你的位置:首页 > ASP.net教程

[ASP.net教程]读取xml格式的字符串和上下文中的xml数据


1、读取

假设有一段下面的

 <     <return_code><![CDATA[SUCCESS]]></return_code>
     <return_msg><![CDATA[OK]]></return_msg>
 </


定义类ClientResponseHandler.cs

public class ClientResponseHandler{   protected Hashtable /* 设置*/    public virtual void setContent(string content)    {      this.content = content;      = new = "");      = root.ChildNodes;      foreach (in xnl)      {        /* 设置*/    public virtual void setContent(string content)    {      this.content = content;      = new = "");      = root.ChildNodes;      foreach (in xnl)      {        

调用:

 rescontent = ""; //假设这里是一段ClientResponseHandler resHandler = new ClientResponseHandler();resHandler.setContent(rescontent);string return_code = resHandler.getMpParameter("return_code"); //return_code是 string return_msg = resHandler.getMpParameter("return_msg"); //return_code是

2、从上下文(Context)读取

假设上下文中(Context)包含一段

 public class ResponseHandler{  private Hashtable public ResponseHandler(HttpContext httpContext)  {    if (this.httpContext.Request.InputStream.Length > 0)    {      = new this.httpContext.Request.InputStream);//这里与上面不同      "");      = root.ChildNodes;              foreach (in xnl)      {                  /* 获取参数值 */  public string getMpParameter(string parameter)  {    string s = (string)return (null == s) ? "" : s;  }}

调用:

 ResponseHandler resHandler = new ResponseHandler(Context);//Context 是HttpContext string return_code = resHandler.getMpParameter("return_code"); //return_code是string return_msg = resHandler.getMpParameter("return_msg"); //return_msg是