예제 #1
0
 /// <summary>
 /// 读取XML返回经排序或筛选后的DataView
 /// </summary>
 /// <param name="strWhere">筛选条件,如:"name='kgdiwss'"</param>
 /// <param name="strSort"> 排序条件,如:"Id desc"</param>
 public DataView GetDataViewByXml(string strWhere, string strSort)
 {
     try
     {
         string  XMLFile  = this.XMLPath;
         string  filename = AppDomain.CurrentDomain.BaseDirectory.ToString() + XMLFile;
         DataSet ds       = new DataSet();
         ds.ReadXml(filename);
         DataView dv = new DataView(ds.Tables[0]); //创建DataView来完成排序或筛选操作
         if (strSort != null)
         {
             dv.Sort = strSort; //对DataView中的记录进行排序
         }
         if (strWhere != null)
         {
             dv.RowFilter = strWhere; //对DataView中的记录进行筛选,找到我们想要的记录
         }
         return(dv);
     }
     catch (Exception e)
     {
         HIO.WriteLog(e);
         return(null);
     }
 }
예제 #2
0
        /// <summary>
        /// 读取指定路径和节点的属性值
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="node">节点</param>
        /// <param name="attribute">属性名,非空时返回该属性值,否则返回串联值</param>
        /// 使用示列:
        /// XMLProsess.Read(path, "/Node", "")
        /// XMLProsess.Read(path, "/Node/Element[@Attribute='Name']", "Attribute")
        public static string Read(string path, string node, string attribute)
        {
            string value = "";

            try
            {
                XmlDocument doc = XMLLoad(path);
                XmlNode     xn  = doc.SelectSingleNode(node);
                value = (attribute.Equals("") ? xn.InnerText : xn.Attributes[attribute].Value);
            }
            catch (Exception e)
            {
                HIO.WriteLog(e);
            }
            return(value);
        }
예제 #3
0
        /// <summary>
        /// 读取指定路径和节点的串联值
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="node">节点</param>
        /// <param name="attribute">属性名,非空时返回该属性值,否则返回串联值</param>
        /// 使用示列:
        /// XMLProsess.Read(path, "/Node", "")
        /// XMLProsess.Read(path, "/Node/Element[@Attribute='Name']")
        public static string ReadValue(string path, string node)
        {
            string value = "";

            try
            {
                XmlDocument doc = XMLLoad(path);
                XmlNode     xn  = doc.SelectSingleNode(node);
                value = xn.InnerText;
            }
            catch (Exception e)
            {
                HIO.WriteLog(e);
            }
            return(value);
        }
예제 #4
0
        /// <summary>
        /// 读取指定节点的数据,属性的值
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="attr">属性</param>
        /// 使用示列:
        /// XMLProsess.Read("/Node/Element[@Attribute='Name']","Attribute")
        /// <returns></returns>
        public string Read(string node, string attr)
        {
            string value = "";

            try
            {
                XmlDocument doc = XMLLoad();
                XmlNode     xn  = doc.SelectSingleNode(node);
                value = xn.Attributes[attr].InnerXml;
            }
            catch (Exception e)
            {
                HIO.WriteLog(e);
            }
            return(value);
        }
예제 #5
0
        private static XmlDocument XMLLoad()
        {
            XmlDocument xmldoc = new XmlDocument();

            try
            {
                string filename = AppDomain.CurrentDomain.BaseDirectory.ToString() + _path;
                if (File.Exists(filename))
                {
                    xmldoc.Load(filename);
                }
            }
            catch (Exception e)
            {
                HIO.WriteLog(e);
            }
            return(xmldoc);
        }
예제 #6
0
 /// <summary>
 /// 读取XML返回DataSet
 /// </summary>
 /// <param name="strXmlPath">XML文件相对路径</param>
 public DataSet GetDataSetByXml(string strXmlPath)
 {
     try
     {
         DataSet ds = new DataSet();
         ds.ReadXml(GetXmlFullPath(strXmlPath));
         if (ds.Tables.Count > 0)
         {
             return(ds);
         }
         return(null);
     }
     catch (Exception e)
     {
         HIO.WriteLog(e);
         return(null);
     }
 }