我有一个XDocument结构如下:
<?xml version="1.0" encoding="utf-8"?>
<body>
<ControlSettings>
<Manual-B nudA="20" nudB="3" nud=D"4" />
<Manual-A nudA="2" nudB="33" nudD="4" />
<Manual-C nudA="20" nudB="20" nudD="40" />
<another value="true" />
</ControlSettings>
<Score>
<Manual-F result="fail" />
</Score>
</body>
我正在尝试输出一个仅包含控制设置中名称的排序列表,以便字符串列表应包含:
如何使用xpath / linq使用Xdocuments? 我在下面试过,但它没有缝合工作
IEnumerable <string> names = doc.XPathSelectElements
("..//body//ControlSettings").Select(e => e.Name.LocalName);
/* other things i tried:
List<string>mnames = doc.Root.Element("..//controlsettings").
var query = from x in doc.Descendants("//body//ControlSettings")
*/
foreach (string localname in names)Console.WriteLine(localname);
答案 0 :(得分:1)
您可以使用function proxChange(proxies, index, val) {
proxies[index] = val;
}
var a = new Proxy({}, {});
var proxies = [];
proxies.push(a);
proxChange(proxies, 0, 2);
console.log(typeof a, a);
console.log(typeof proxies[0], proxies[0]);
Descendants
或者,如果这是广泛的,并且您想要特定于ControlSettings组,您可以像下面那样挖掘
xmlDoc.Descendants()
.Where(e => e.Name.LocalName.Contains("Manual"))
.Select(e => e.Name.LocalName)
.OrderBy(e => e)
.ToList();