sql server 2005 生成xml问题
下面是获取用户的权限列表根据权限列表生产XML文件
下面代码如何改造成一个存储过程接受一个Psn_ID参数 生成xml文件 返回
XmlDocument xmldoc = new XmlDocument();
StringBuilder sb = new StringBuilder();
var query = upl.OrderBy(o => o.Rig_RR_ID).ToList();
var query1 = (from o in kp.V_UserRight.Where(o => o.Psn_ID == wp[0].Psn_ID && o.RR_Flag == "启用" && o.UR_State == "启用")
group o by o.Rig_RR_ID into p
select new
{
p.Key,
RitList = (from q in query
where q.Rig_RR_ID == p.Key
group q by q.Group_ID into a
select new
{
a.Key,
RitList = query.Where(r => r.Group_ID == a.Key).ToList()
}).ToList()
}).ToList();
sb.Append(" <Ribbon>");
for (int i = 0; i < query1.Count; i++)
{
sb.AppendFormat(" <RibbonPage Name='{0}' Text='{1}'>", "rp" + i, kp.Right_Right.SingleOrDefault(o => o.RR_ID == query1.ElementAt(i).Key).RR_Name);
for (int j = 0; j < query1.ElementAt(i).RitList.Count; j++)
{
sb.AppendFormat(" <RibbonPageGroup Name='{0}' Text='{1}'>", "rpg" + j, query1.ElementAt(i).RitList.ElementAt(j).Key);
for (int k = 0; k < query1.ElementAt(i).RitList.ElementAt(j).RitList.Count; k++)
{
sb.AppendFormat(" <BarButtonItem Name='{0}' Caption='{1}' NameSpace='{2}'/>", query1.ElementAt(i).RitList.ElementAt(j).RitList[k].RR_Name, query1.ElementAt(i).RitList.ElementAt(j).RitList[k].RR_Caption, query1.ElementAt(i).RitList.ElementAt(j).RitList[k].RR_NameSpace);
}
sb.Append(" </RibbonPageGroup>");
}
sb.Append(" </RibbonPage>");
}
sb.Append(" </Ribbon>");
xmldoc.LoadXml(string.Format(" <?xml version='1.0' encoding='gb2312'?>{0}", sb));
xmldoc.Save(userconfig);
<?xml version="1.0" encoding="utf-8" ?><Ribbon><RibbonPage Name="rpXS" Text="销售管理"> <RibbonPageGroup Name="LSrpg1" Text="销售管理"> <BarButtonItem Name="KPTech.PosSaleFrmItems.DrgSale.FrmSaleIn" NameSpace="KPTech.PosSaleFrmItems" Caption="销售录入" /> <BarButtonItem Name="KPTech.PosSaleFrmItems.DrgSale.FrmDaySaleQuery" NameSpace="KPTech.PosSaleFrmItems" Caption="销售记录查询" /> <BarButtonItem Name="KPTech.PosSaleFrmItems.DrgSale.FrmBusinessIn" NameSpace="KPTech.PosSaleFrmItems" Caption="上缴营业款" /> <BarButtonItem Name="KPTech.PosSaleFrmItems.DrgSale.FrmPsnChange" NameSpace="KPTech.PosSaleFrmItems" Caption="交接班" /> </RibbonPageGroup> </RibbonPage></Ribbon>
select (select rr_name from right_ritht where r1.rig_rr_id=rr_id) [@Text], (select group_id [@Text], (select rr_name [@Name],rr_namespace [@Namespace],rr_caption [@Caption] from rview where r2.group_id=group_id for xml path('BarButtonItem'),type) from rview r2 where r1.rig_rr_id=rig_rr_id group by group_id for xml path('RibbonPageGroup'),type)from rview r1 where psn_id=@id group by rig_rr_idfor xml path('RibbonPage'),root('Ribbon');