可以使用System.XML命名空间中的类如:
System.Xml.XmlDocument类的LoadXml方法来从指定的字符串加载 XML 文档。 

解决方案 »

  1.   

    可尝试汇入 using System.Xml 后,自己用 .net 内建的 读、写 XML 的 API 去写一支简单的文件读取、解析函数。using System.Xml;public string ReadXML(string strUser_No, string strFunc_No)
    {
        string str_SFUNC_NO = null;    // 读取位于 ~/App_Data/xml 目录中的 XML
        XmlDocument doc = new XmlDocument();
        string FilePath = null;
        FilePath = HttpContext.Current.Server.MapPath("~/App_Data/xml/" + strUser_No + ".xml");
        doc.Load(FilePath);
        //doc.Load(Server.MapPath("../../App_Data/xml/" + strUser_No + ".xml"));    XmlNodeList nodeList;
        XmlNode root = doc.DocumentElement;    // 既有的 XML 档里,有几个「USER_NO」Tag,待会循环就跑几次
        nodeList = root.SelectNodes("//NewDataSet/DataTable2/USER_NO/text()");      // 跑循环,把 App_Data/xml 目录中,存储有关这支程序其权限的 XML 文件,把内容全都读出来
        for (int i = 0; i <= nodeList.Count - 1; i++)
        {
            if (root.SelectNodes("//NewDataSet/DataTable2/FUNC_NO/text()").Item(i).Value == strFunc_No.Trim())
            {
                // 
                str_SFUNC_NO = root.SelectNodes("//NewDataSet/DataTable2/SFUNC_NO/text()").Item(i).Value;                                break;    // 跳出 loop
            }
        }    return str_SFUNC_NO;
    }
      

  2.   

    using System.Xml;public string ReadXML(string strUser_No, string strFunc_No)
    {
        string str_SFUNC_NO = null;    // 读取位于 ~/App_Data/xml 目录中的 XML
        XmlDocument doc = new XmlDocument();
        string FilePath = null;
        FilePath = HttpContext.Current.Server.MapPath("~/App_Data/xml/" + strUser_No + ".xml");
        doc.Load(FilePath);
        //doc.Load(Server.MapPath("../../App_Data/xml/" + strUser_No + ".xml"));    XmlNodeList nodeList;
        XmlNode root = doc.DocumentElement;    // 既有的 XML 档里,有几个「USER_NO」Tag,待会循环就跑几次
        nodeList = root.SelectNodes("//NewDataSet/DataTable2/USER_NO/text()");      // 跑循环,把 App_Data/xml 目录中,存储有关这支程序其权限的 XML 文件,把内容全都读出来
        for (int i = 0; i <= nodeList.Count - 1; i++)
        {
            if (root.SelectNodes("//NewDataSet/DataTable2/FUNC_NO/text()").Item(i).Value == strFunc_No.Trim())
            {
                // 
                str_SFUNC_NO = root.SelectNodes("//NewDataSet/DataTable2/SFUNC_NO/text()").Item(i).Value;                                break;    // 跳出 loop
            }
        }    return str_SFUNC_NO;
    }
      

  3.   

    using System.Xml;          XmlDocument doc = new XmlDocument();
                string strFileName = AppDomain.CurrentDomain.BaseDirectory.ToString() + "TEST.exe.config";
                                                                            //此中 TEST 为你程序名称
                doc.Load(strFileName);            XmlNodeList nodes = doc.GetElementsByTagName("General");    //找到名称为General所有元素
                for (int i = 0; i < nodes[0].Attributes.Count; i++)
                {
                    try
                    {
                        Console.WriteLine(nodes[0].Attributes[i].Name + "  " + nodes[0].Attributes[i].Value);
                        //前一个为 属性名称,            后一个为 键值
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
      

  4.   

    http://blog.csdn.net/llwinnner/archive/2009/03/18/4002739.aspx
    你看看吧
      

  5.   

    XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(@"C:\Documents and Settings\Administrator\桌面\作业\Lesson5XML\Lesson5XML\XMLFile1.xml");            XmlElement xmlEle = xmlDoc.DocumentElement;
                //MessageBox.Show(xmlEle.Name);
                TreeNode node = null;
                foreach(XmlNode xmlNode in xmlEle.ChildNodes)
                {
                switch(xmlNode.Name)
                {
                    case"name":
                        node = new TreeNode();    //treeview的根节点
                        node.Text = xmlNode.InnerText;    //提取中间值
                        this.treeView1.Nodes.Add(node);
                        break;
                    case"age":
                        node.Nodes.Add(xmlNode.InnerText);
                        break;
                    case"hobby":
                        node.Nodes.Add(xmlNode.InnerText);
                        break;
                }
                }
    循环读取
      

  6.   

    最简单的方式就是使用Linq 2 XML了。
    上MSDN看看XDocument的用法。