private readonly string _roleXmlPath = HttpContext.Current.Server.MapPath("~/App_XMLs/Roles.xml");
private readonly string _companyXmlPath = HttpContext.Current.Server.MapPath("~/App_XMLs/Companys.xml"); public StringBuilder GetAllRoles()
{
StringBuilder reVal = new StringBuilder(); //定义一个变量
XDocument xDoc = XDocument.Load(_roleXmlPath);
var roles = from x in xDoc.Descendants("role") select x;
reVal.Append("[");
foreach (XElement e in roles)
{
if (reVal.Length > 1) { reVal.Append(","); }
reVal.Append("{\"text\":\"" + e.Element("text").Value + "\",\"value\":\"" + e.Element("value").Value + "\"}");
}
reVal.Append("]");
return reVal;
}这个看不是很懂,求专业人士给分析一下,最好能写一下注释,谢谢
private readonly string _companyXmlPath = HttpContext.Current.Server.MapPath("~/App_XMLs/Companys.xml"); public StringBuilder GetAllRoles()
{
StringBuilder reVal = new StringBuilder(); //定义一个变量
XDocument xDoc = XDocument.Load(_roleXmlPath);
var roles = from x in xDoc.Descendants("role") select x;
reVal.Append("[");
foreach (XElement e in roles)
{
if (reVal.Length > 1) { reVal.Append(","); }
reVal.Append("{\"text\":\"" + e.Element("text").Value + "\",\"value\":\"" + e.Element("value").Value + "\"}");
}
reVal.Append("]");
return reVal;
}这个看不是很懂,求专业人士给分析一下,最好能写一下注释,谢谢
解决方案 »
- |zyciis| ClientScript.RegisterClientScriptResource是加入资源到网页的,他都是放在Form开头的,能不能放在Form结尾啊,谢谢
- 未知的服务器标记“customEditors:Lite
- ExtJS整合KindEditor的小毛病,该怎么解决?
- asp.net(C#)中如何在网页关闭的时候执行某个操作?
- 很简单的自定义控件问题,知道的指点一下
- 救命:同样的CR做的报表在一台机器上运行可以,可是在另一台上出错,报错是:ADODB文件没找到,请高手指点,先放100分,错误信息请近来看看(
- 各位大侠,小女子刚学ASP.NET,有个关于广告旋转板的问题想请教,谢谢!
- 急问安装VS.NET 2003需要什么操作系统?
- 请问大家?
- vs.net2003安装出错!!!!!!!重试了10次。。。!!!
- vs2008解决方案的一个奇怪问题? 急 急 急
- IETester
private readonly string _companyXmlPath = HttpContext.Current.Server.MapPath("~/App_XMLs/Companys.xml");//路径常量 public StringBuilder GetAllRoles()
{
StringBuilder reVal = new StringBuilder(); //定义一个变量
XDocument xDoc = XDocument.Load(_roleXmlPath);//加载XML
var roles = from x in xDoc.Descendants("role") select x;//延迟读取XML信息
reVal.Append("[");//将读取出的XML信息以JSON的格式存储到StringBuilder字符串变量reVal中
foreach (XElement e in roles)
{
if (reVal.Length > 1) { reVal.Append(","); }
reVal.Append("{\"text\":\"" + e.Element("text").Value + "\",\"value\":\"" + e.Element("value").Value + "\"}");
}
reVal.Append("]");
return reVal;
}
var roles = from x in xDoc.Descendants("role") select x;//延迟读取XML信息foreach (XElement e in roles)
{
if (reVal.Length > 1) { reVal.Append(","); }
reVal.Append("{\"text\":\"" + e.Element("text").Value + "\",\"value\":\"" + e.Element("value").Value + "\"}");
}
private readonly string _companyXmlPath = HttpContext.Current.Server.MapPath("~/App_XMLs/Companys.xml"); //定义两个只读字符串变量保存两个xml文件的绝对路径 public StringBuilder GetAllRoles()
{
StringBuilder reVal = new StringBuilder(); //定义一个字符串变量reVal
XDocument xDoc = XDocument.Load(_roleXmlPath); //读取xml数据
var roles = from x in xDoc.Descendants("role") select x; //从xml数据中查找role的所有节点
reVal.Append("["); //reVal加上字符"[" foreach (XElement e in roles) //循环role这个xml节点,
{
if (reVal.Length > 1) { reVal.Append(","); } //如果reVal长度大于1则加一个字符,
reVal.Append("{\"text\":\"" + e.Element("text").Value + "\",\"value\":\"" + e.Element("value").Value + "\"}"); //regVal循环添加字符串格式是这样的 {"text":"role节点下text的值","value":"role节点下value的值"}
}
reVal.Append("]");
return reVal;
}
那个X是干嘛用的啊