public interface IXmlAnalyze
{
object GetXmlModel(Page page, string dataKey);
}
public class XmlAnalyze : IXmlAnalyze
{
public static DataSet XmlDataSet = new DataSet("XmlDataSet");
private string filePath = string.Empty;
public XmlAnalyze()
{
filePath = "/Resources/XML/TextBoxSelect.xml";
}
/// <summary>
/// Relative path
/// </summary>
/// <param name="filePath"></param>
public XmlAnalyze(string filePath)
{
this.filePath = filePath;
}
protected void LoadXMLData(Page page)
{
string fileAbsPath = page.Server.MapPath(filePath);
//xmlDoc.Load(fileAbsPath);
XmlDataSet.ReadXml(fileAbsPath,XmlReadMode.ReadSchema);
}
public virtual object GetXmlModel(Page page, string dataKey)
{
if (!XmlDataSet.Tables.Contains("TextBoxSelect"))
{
LoadXMLData(page);
}
if (!XmlDataSet.Tables.Contains("TextBoxSelect")) return null;
foreach (DataRow dr in XmlDataSet.Tables["TextBoxSelect"].Rows)
{
if (dr["DataKey"].ToString().ToLower() == dataKey.ToLower())
{
TextBoxSelectXmlModel model = new TextBoxSelectXmlModel();
model.DataKey = dataKey;
model.TableName = dr["TableName"].ToString();
model.ShowFields = dr["ShowFields"].ToString();
model.Title = dr["Title"].ToString();
model.ShowFieldsHeader = dr["ShowFieldsHeader"].ToString();
model.ValueTextFields = dr["ValueTextFields"].ToString();
model.FieldWidth = dr["FieldWidth"].ToString();
model.HiddenFields = dr["HiddenFields"].ToString();
model.SearchFields = dr["SearchFields"].ToString();
model.SearchFieldsHeader = dr["SearchFieldsHeader"].ToString();
model.Where = dr["Where"].ToString();
model.Order = dr["Order"].ToString();
model.CallBackParams = dr["CallBackParams"].ToString();
return model;
}
}
return null;
}
}
[Serializable]
public class TextBoxSelectXmlModel
{
public string DataKey { get; set; }
public string TableName { get; set; }
public string Title { get; set; }
public string ShowFields { get; set; }
public string ShowFieldsHeader { get; set; }
public string ValueTextFields { get; set; }
public string FieldWidth { get; set; }
public string HiddenFields { get; set; }
public string SearchFields { get; set; }
public string SearchFieldsHeader { get; set; }
public string Where { get; set; }
public string Order { get; set; }
public string CallBackParams { get; set; }
}
这是XML文件的分析工具
玩技术,要学会忍受寂寞--