System.TypeLoadException:无法从程序集“System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”加载类型“System.Web.HttpContext”。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Xml.Linq;
public class Example :
{
XDocument doc = XDocument.Load(System.Web.HttpContext.Current.Server.MapPath("~/example.xml"));
}
Run Code Online (Sandbox Code Playgroud) 在C#中使用XML文件,我正在尝试将XPath查询转换为LINQ,我不知道如何实现最后一节:
XPath的:
variable.XPathSelectElements("procedures/menu[@id='value']/procedure[@id]")
Run Code Online (Sandbox Code Playgroud)
LINQ:
from el in variable.Descendants("procedures").Descendants("menu")
where el.Element("id").Value == "value"
Run Code Online (Sandbox Code Playgroud)
我已经修改了你的建议@Jon但我似乎在这里做了一个我无法解决的简单错误.
XDocument doc = XDocument.Load("procedures.xml");
var query = doc.Elements("procedures")
.Elements("menu")
.Where(x => (string) x.Attribute("id") == "value")
.Elements("procedure").Where(x => x.Attribute("id") != null);
public List<string> commands = new List<string>();
foreach (XElement procedure in query) {
commands.Add(procedure.Attribute("id"));
}
Run Code Online (Sandbox Code Playgroud) 我应该如何最好地转换元素
List<string> icons
Run Code Online (Sandbox Code Playgroud)
至:
List<Texture> icons
Run Code Online (Sandbox Code Playgroud)
我从XML文件中提取文件名(因此是初始字符串格式),但我想将文件名转换为纹理格式,因为它们是在运行时动态形成的,所以我无法从检查器加载.