本帖最后由 sb19871023 于 2009-07-27 14:15:04 编辑

解决方案 »

  1.   

    就是直接用readxml 就可以了 只是可能在不同的table里
      

  2.   

    给你个关于XML的类 你看看
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Xml;
    using System.Collections; /// <summary>
    /// TXml 的摘要说明
    /// </summary>
    public class TXml
    {
        /// <summary>
        /// XML操作类
        /// </summary>
        public TXml()
        {
            //
            // TODO:
            //
        }    XmlDocument XD = new XmlDocument();
        /// <summary>
        /// 在xml文件内查询数据
        /// </summary>
        /// <param name="XmlFilePath">Xml文件</param>
        /// <param name="XmlPath">XPath条件</param>
        /// <returns>返回查询到的内容</returns>
        public XmlNode DataFind(string XmlFilePath, string XmlPath)
        {
            XD.Load(XmlFilePath);
            return XD.SelectSingleNode(XmlPath);
        }    /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="XmlFilePath">Xml文件</param>
        public void Save(string XmlFilePath)
        {
            XD.Save(XmlFilePath);
        }    /// <summary>
        /// 获得子节点个数
        /// </summary>
        /// <param name="XmlFilePath">Xml路径</param>
        /// <param name="XmlPath">XPath条件</param>
        /// <returns></returns>
        public int GetLineCount(string XmlFilePath, string XmlPath)
        {
            XmlNode Xl = DataFind(XmlFilePath, XmlPath);
            return Xl == null ? 0 : Xl.ChildNodes.Count;
        }    /// <summary>
        /// 自定义数据绑定
        /// </summary>
        /// <param name="XmlFilePath">xml文件路径</param>
        /// <param name="XmlPath">XPath 搜索条件</param>
        /// <param name="SortKey">排序关键字</param>
        /// <returns>返回与DataSource相对应的借口</returns>
        public ICollection CreateDataSource(string XmlFilePath, string XmlPath, string SortKey)
        {
            DataTable dt = new DataTable();
            DataRow dr;
            DataView dv = null;        try
            {
                XD.Load(XmlFilePath);            XmlNodeList xl = XD.SelectNodes(XmlPath);            if (xl != null && xl.Count > 0)
                {
                    int j;
                    for (j = 0; j < xl[0].Attributes.Count; j++)
                    {
                        dt.Columns.Add(new DataColumn(xl[0].Attributes.Item(j).LocalName, typeof(string)));
                    }                dt.Columns.Add(new DataColumn(xl[0].LocalName, typeof(string)));                for (int i = 0; i < xl.Count; i++)
                    {
                        dr = dt.NewRow();
                        for (j = 0; j < xl[i].Attributes.Count; j++)
                        {
                            dr[j] = xl[i].Attributes.Item(j).InnerText;                    }
                        dr[j] = xl[i].InnerText;
                        dt.Rows.Add(dr);
                    }            }
                dv = new DataView(dt);
                dv.Sort = SortKey;
            }
            catch
            { }
            return dv;
        }    /// <summary>
        /// 通用CDATA数据写入
        /// </summary>
        /// <param name="strFilePath">路径</param>
        /// <param name="strData">数据</param>
        /// <param name="strNote">注释</param>
        /// <param name="strXslFile">解释的xsl文件 可以不写</param>
        public void WriteXml(string strFilePath, string strData, string strNote, string strXslFile)
        {
            XmlTextWriter XmlFile = new XmlTextWriter(strFilePath, null);
            try
            {
                XmlFile.Formatting = Formatting.Indented;
                XmlFile.Indentation = 3;
                XmlFile.WriteStartDocument();
                if (strXslFile != "")
                {
                    XmlFile.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='" + strXslFile + "'");
                }
                XmlFile.WriteComment("Create @" + DateTime.Now.ToString());
                XmlFile.WriteComment(strNote);
                XmlFile.WriteStartElement("DB");
                XmlFile.WriteCData(strData);
                XmlFile.WriteEndElement();
                XmlFile.WriteEndDocument();
            }
            catch
            {        }
            XmlFile.Close();
        }
    }
      

  3.   

    用了!不可以!提供的 Xml 实例是一个架构或包含内嵌架构。该类无法针对某架构来推断架构。报这个异常