ASP.Net中读取XML的方法总结

在ASP.Net中有很多种方法读取XML,在这里简单的总结一下:
1. XmlDocument方法:
 1 XmlDocument doc  =   new  XmlDocument();
 2             XmlNode root  =   null ;
 3             XmlNodeList nodes  =   null ;
 4             doc.Load(HttpContext.Current.Server.MapPath( " ~/App_Data/Workflow.xml " ));
 5             root  =  doc.DocumentElement;
 6             nodes  =  root.SelectNodes( " /TeamTrack/Workflow " );
 7              foreach  (XmlNode node  in  nodes)
 8              {
 9                if (node.Attributes["ID"].Value == row["Workflow_ID"].ToString())
10                    this.WorkflowName = node.Attributes["Name"].Value;
11                else
12                    this.WorkflowName = "";
13            }

2. XmlTextReader方法:
 1 XmlTextReader reader  =   new  XmlTextReader(HttpContext.Current.Server.MapPath( " ~/App_Data/Workflow.xml " ));
 2                  while  (reader.Read())
 3                  {
 4                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "Workflow")
 5                    {
 6                        if (dl_task.Workflow_ID == reader["ID"])
 7                        {
 8                            workflowtype = reader["Type"].ToString();
 9                            break;
10                        }

11                    }

12                }

你可能感兴趣的:(asp.net)