xml的读取(曾删改)
获取XML 得到 需要查询的字段名
private string GetXml(string TableName) {
try
{
string TbName = TableName.Split('_')[TableName.Split('_').Length - 1].ToString();
string path = System.AppDomain.CurrentDomain.BaseDirectory;
XElement xe = XElement.Load(@"" + path + "\\Configs\\PageConfig\\Query\\PagePermission.xml");//xml文件所在位置
IEnumerable<XElement> elements = from ele in xe.Elements("PagePermission") select ele;//linq 方式查询xml内容
IEnumerable<XElement> Pages = from ele in elements.Elements("Pages") select ele;//拿到PagePermission 下的子节点 也可以根据.Elements(); 拿到子节点
IEnumerable<XElement> Page = from ele in Pages.Elements("Page") where (string)ele.Attribute("PageAuthCode") == TbName select ele;//筛选所需的Page
string Code = "";
foreach (var p in Page)
{
IEnumerable<XElement> MultiFuzzyQuerys = from ele in p.Elements("MultiFuzzyQuerys") select ele;//linq 方式查询xml内容
MultiFuzzyQuerys = MultiFuzzyQuerys.Elements();
var MultiFuzzyQuery = MultiFuzzyQuerys.Elements();
int i = 1;
foreach (var m in MultiFuzzyQuery)
{
if (i == MultiFuzzyQuery.Count())
{
Code += (string)m.Attribute("Code");
}
else
{
Code += (string)m.Attribute("Code") + "-";
}
i++;
}
}
return Code;
}
catch (Exception)
{
return "";
//throw;
}
}
参考
https://www.cnblogs.com/a1656344531/archive/2012/11/28/2792863.html